怎样用java获得局域网内所有机器的IP??
xhzuo 2003-12-06 09:52:47 在网上搜索了一段程序,但是只能显示本机的IP。
有没有其他可以用的程序??
import java.net.NetworkInterface;
import java.util.Enumeration;
public class ShowAllNetworkInterface {
public static void main(String[] args) {
NetworkInterface nif;
try{
Enumeration em = NetworkInterface.getNetworkInterfaces();
while (em.hasMoreElements()) {
nif = (NetworkInterface)em.nextElement();
System.out.print(nif.getDisplayName());
Enumeration me = nif.getInetAddresses();
while(me.hasMoreElements()){
System.out.print(" : " + me.nextElement());
}
System.out.println();
}
}
catch(Exception e){
}
}
}