Topic: 求助(在局域网内如何获得所有网络计算机的名字和ip) |
Print this page |
1.求助(在局域网内如何获得所有网络计算机的名字和ip) | Copy to clipboard |
Posted by: cqlgc Posted on: 2003-11-22 14:23 请问在局域网内部,如何获得所有的网络计算机。计算机的名字和ip地址! |
2.Re:求助 [Re: cqlgc] | Copy to clipboard |
Posted by: lcwling Posted on: 2003-11-22 21:46 如果要用j纯ava语言实现,我想恐怕很难吧 !如果在windows下,自己编写jni可能就容易一些,关注.... |
3.Re:求助(在局域网内如何获得所有网络计算机的名字和ip) [Re: cqlgc] | Copy to clipboard |
Posted by: alin_ass Posted on: 2003-11-23 20:16 贴以前写的,有个小问题,我不懂jdk的,请问为什么这个类我用起来有时搜索结果,并且返回没有结果的时间太长了,怎么设置超时就算无效ip,请高手支援 /* ------------------------------------------------------------------ * Copyright: Free software. * Author: Alin&ASS(AlinSoftStudio) * Email: alin_ASS@hotmail.com * Time: 12:33:00 2003-11-9 * Project:alinjava * Readme: If you make any modification or have some advice * about this application, I am very glad to know about it. * * Description: Gain a list of machinenames to specified * address in LAN(local area network). The result may not be * complete. I guess simplicity it it becuase of the thread * which use the java.net.InetAddress.getByAddress(byte[]) * will blocked in the Scoket(the more threads the worse)so * as to lose some machinenames. * ------------------------------------------------------------------ */ import java.net.*; /** * Gain a list of machinenames between * address 192.168.0.x~192.168.0.y. * (1<=x<y<=255) * here x and y is specified in main() * method's arguments. * In winOS blank and dot can't be used * in a machinename. * Notice, for example, number 192 in law * IP is -64( it is just <code>(byte)192</code>. * Because law IP use byte numbers. */ public class GainMacNamesInLAN { private int startIP4th = 1; private int endIP4th = 255; private int macNums = 0; private int IP4th = 1; private int sleepedExplorerNums = 0; private int explorerNums = 0; private long startExplorerTime = 0L; private long endExplorerTime = 0L; private class PrintEndStatus extends Thread { private boolean runFlag = false; public void run() { while (true) { if (runFlag) { if (sleepedExplorerNums == explorerNums) { endExplorerTime = System.currentTimeMillis(); printEndInfo(); runFlag = false; System.exit(1); } } else { sleep(); } } } public void start() { if (!runFlag) { runFlag = true; super.start(); } } public void sleep() { try { Thread.sleep(100000); } catch (InterruptedException e) { } } } // end class private class IPExploreThread extends Thread { private boolean runFlag = false; private String hostname = null; private int nowIP4th = 1; public void run() { while (true) { if (runFlag) { nowIP4th = getNextIP4th(); if (nowIP4th == 0) { runFlag = false; addSleepExplorerNums(); } else { try { hostname = InetAddress .getByAddress( new byte[] { -64, -88, 0, (byte) nowIP4th }) .getHostName(); } catch (UnknownHostException e) { } if (hostname.length() > 10 && hostname.substring(0, 4).equals("192.")) { } else { System.out.println( hostname + " / 192.168.0." + nowIP4th); addMacNums(); } } } else { sleep(); } } } public void start() { if (!runFlag) { runFlag = true; super.start(); } } public void sleep() { try { Thread.sleep(1000000); } catch (InterruptedException e) { } } } //end class private void addMacNums() { macNums++; } private void addSleepExplorerNums() { sleepedExplorerNums++; } private void printStartInfo() { System.out.println( "\n\n********** Welcome to use IP Explorer version1.0 ***********"); System.out.println( "Start exploring, using " + explorerNums + " explorers...\n"); } private void printEndInfo() { System.out.println( "\nIP exploring process is finished.\nTotal " + macNums + " machines between 192.168.0." + startIP4th + " to 192.168.0." + endIP4th + " ."); System.out.println( "Waste time: " + (endExplorerTime - startExplorerTime) / 1000L + " seconds."); System.out.println( "************************* alin&ASS *************************"); } private synchronized int getNextIP4th() { if (IP4th > endIP4th) { return 0; } /我要记住下行这样写是可以的 return IP4th++; } /** * Initialize explorer. * @param startAddress start IP's fourth segment * @param endAddress end IP's fourth segment * @param threadNums explorer nums */ private void startIPExploreThreadBetween( int startAddress, int endAddress, int threadNums) { startIP4th = startAddress; IP4th = startIP4th; endIP4th = endAddress; int IPNums = endIP4th - startIP4th + 1; if (IPNums < threadNums) { explorerNums = IPNums; } else { explorerNums = threadNums; } printStartInfo(); startExplorerTime = System.currentTimeMillis(); for (int i = 0; i < explorerNums; i++) { new IPExploreThread().start(); } new PrintEndStatus().start(); } public static void main(String[] args) { GainMacNamesInLAN alinLAN = new GainMacNamesInLAN(); if (args.length == 3) { alinLAN.startIPExploreThreadBetween( Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2])); } else { alinLAN.startIPExploreThreadBetween(1, 50, 10); } } } ------------------------ >java GainMacNamesInLAN 1 255 20 在我机子上的结果: ********** Welcome to use IP Explorer version1.0 *********** Start exploring, using 20 explorers... SK.mshome.net / 192.168.0.3 hong-7i9pfrfq32.mshome.net / 192.168.0.10 yangcat-1314.mshome.net / 192.168.0.1 ass / 192.168.0.2 hongmo.mshome.net / 192.168.0.34 lubing.mshome.net / 192.168.0.93 legend-qxanppz6.mshome.net / 192.168.0.121 jiangzuen.mshome.net / 192.168.0.129 zhoulian.mshome.net / 192.168.0.140 yangkefeng.mshome.net / 192.168.0.141 supu-comp.mshome.net / 192.168.0.145 fuqianjie.mshome.net / 192.168.0.155 fangbin.mshome.net / 192.168.0.161 jtime.mshome.net / 192.168.0.191 IP exploring process is finished. Total 14 machines between 192.168.0.1 to 192.168.0.255 . Waste time: 124 seconds. ************************* alin&ASS ************************* |
4.Re:求助(在局域网内如何获得所有网络计算机的名字和ip) [Re: cqlgc] | Copy to clipboard |
Posted by: cqlgc Posted on: 2003-11-24 13:12 getByAddress()时怎么用的,那个byte[] 参数是什么意思。 例如,如何得到IP地址为192.168.0.100 的计算机的名字。 |
5.Re:求助(在局域网内如何获得所有网络计算机的名字和ip) [Re: cqlgc] | Copy to clipboard |
Posted by: nothing Posted on: 2003-11-24 13:24 http://java.sun.com/j2se/1.4.2/docs/api/java/net/InetAddress.html |
6.Re:求助(在局域网内如何获得所有网络计算机的名字和ip) [Re: cqlgc] | Copy to clipboard |
Posted by: alin_ass Posted on: 2003-11-24 22:51 用(byte)转型 192---》 -64 168---》 -88 .... String hostname = InetAddress .getByAddress( new byte[] { -64, -88, 0, 100}) .getHostName(); |
7.Re:求助(在局域网内如何获得所有网络计算机的名字和ip) [Re: cqlgc] | Copy to clipboard |
Posted by: alin_ass Posted on: 2003-11-24 22:55 可是如果没找到它会不停找,估计要半分钟多才返回失败(就是主机名为ip), 我不知道怎么改失败时间,只好用多线程了... |
8.Re:求助(在局域网内如何获得所有网络计算机的名字和ip) [Re: cqlgc] | Copy to clipboard |
Posted by: alin_ass Posted on: 2003-11-26 19:05 问: 为什么在Windows平台上用Naming.lookup来获取远程RMI对象时会很慢? 答: 机器的网络设置不正确很可能会引起该问题的发生. RMI使用了Java网络类,特别是java.net.InetAddress类,它将查询TCP/IP的主机名, 包括IP地址到主机名的映射和主机名到IP地址的映射.在Windows平台,这种查询功能 是由本地的Windows Socket库来实现的. 因此延时是发生在Windows库中,而非RMI中. 如果你的机器设置成使用DNS,问题通常是DNS服务器查不到主机名,你所发现的延时 是DNS查询的延时. 请尝试将RMI通信中涉及到的所有主机名/IP地址加到本地文件 winntsystem32driversetchosts或windowshosts中. 格式如下: IP地址 主机名 如此设置应当可以明显地减少查询所花的时间. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |