如何获得局域网内的所有计算机IP? 如题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我只知道用软件:Lansee,LanHelper,扫一下你所在的网段,在线的主机都可以扫的到的。 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 classprivate 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 classprivate 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);}}}也有这位同仁的方法可行呀 你不防试一下,在本地是可以实现的呀,用jdk1.5以上的编辑 用SOCKET循环连你所在的局域网IP段能连上就代表此计算机在局域网内 arp,ping等都可以,利用SNMP也可以在交换机上得到MAC和IP 多线程死锁是怎么回事? 坛子里面有熟悉havi的么? "illegal start of expression" 每输入一次参数,文件就重新读取一次吗? 关于JXTA中MessageImpl类 在线等!一个莫名其妙的问题!!!!! 没分了 但是还是要来闻问一问;祝大家过个愉快的世界杯只月 jdk 快疯了,帮帮我吧! jar文件是怎么回事 JAVA编码基础练习题 想要的朋友自己复制吧! 关于使用JTAPI实现modem拔号例子提问
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 classprivate 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 classprivate 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);
}
}
}也有这位同仁的方法可行呀
能连上就代表此计算机在局域网内