String host=null;
int a,b,c,d;
a=192;
b=168;
c=0;
for (d=0;d<=255;d++)
{
  host=a+"."+b+"."+c+"."+d;
  java.net.InetAddress hostAddress=java.net.InetAddress.getByName(host);
  String hostName=hostAddress.getHostName();
  System.out.println(hostName);
}可以的,没有主机名的就是局域网的。。但是比较慢。。没有办法了

解决方案 »

  1.   

    yuebenxian(飘逸) 提供的是思路啊,然后从本机ip地址得到a,b,c,然后循环应该可以。别发牢骚了。
      

  2.   

    加上多线程后速度还是非常快的。例如:int a;
            int b;
            int c;
            int d;        a = 192;
            b = 168;
            for(c = 1; c <= 1; c++) {
                for(d = 0; d <= 255; d++) {
                    final String host = a + "." + b + "." + c + "." + d;                    new Thread() {
                            public void run() {
                                InetAddress hostAddress = null;                            try {
                                    hostAddress = java.net.InetAddress.getByName(host);
                                    if(!hostAddress.getHostName().equalsIgnoreCase(hostAddress.getHostAddress()))
                                 System.out.println(hostAddress.getHostName());
                                }
                                catch(UnknownHostException ex) {
                                }
                            }
                        }.start();
                }
            }