Note that there are some explanatory texts on larger screens.

plurals
  1. PODetecting all available network's broadcast addresses in Java
    text
    copied!<p>For my project I wanted to get a list of all available broadcast addresses so I could broadcast a request and my other application located on other computer in the unspecified network would respond and to get the list I (now using little modified version with contribution of Mike) came up with this:</p> <pre> <code> private ArrayList&lt;InetAddress> getBroadcastAddresses() { ArrayList&lt;InetAddress> listOfBroadcasts = new ArrayList(); Enumeration list; try { list = NetworkInterface.getNetworkInterfaces(); while(list.hasMoreElements()) { NetworkInterface iface = (NetworkInterface) list.nextElement(); if(iface == null) continue; if(!iface.isLoopback() && iface.isUp()) { System.out.println("Found non-loopback, up interface:" + iface); Iterator it = iface.getInterfaceAddresses().iterator(); while (it.hasNext()) { InterfaceAddress address = (InterfaceAddress) it.next(); System.out.println("Found address: " + address); if(address == null) continue; InetAddress broadcast = address.getBroadcast(); if(broadcast != null) listOfBroadcasts.add(broadcast); } } } } catch (SocketException ex) { return new ArrayList&lt;InetAddress>(); } return site; } </code> </pre> <p>It works quite well for reqular LAN however when it comes to the WiFi LAN it just skips the second while loop after one step because of having <code>address</code> equals null even though when I used <code>System.out.println(interfaceItem)</code> just to view what interfaces are being gone through it wrote wireless LAN's name and my IP corresponding to the network.</p> <p><b>EDIT 1:</b> <a href="http://aetips.wz.cz/output.txt" rel="noreferrer">This</a> is the output where 172.16.1.104 is my IP in the wireless network. The problem appears ONLY on my notebook with Wifi. The output is from my notebook where I mostly use wireless and sometimes I use UTP to connect with my friend. There is also one network interface of VirtualBox on my notebook.</p> <p>Could you tell me what's wrong with it? Thank you!</p> <p><i>Note: So it turns out that this might be problem for my notebook in particular and the code works for everybody else in general, I love this kind of problem :-) Seems like a dead end to me but thank for help anyway :-)<br><br>Still love you! ;-)</i></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload