hi
ich brauch ma noch n paar meinungen daher auch doppelpost über 2 foren:
wie ich in http://www.java-forum.org/de/topic55958_socket.html schon beschrieben hab:
ich habe anhand des links von slaterb mir die variante rausgesucht wie ich das netzwerk nach bestimmten rechnern absuch... leider ist es so das je mehr sockets ich auf und zu mach umso länger braucht er ... das is dann irgendwann so lang das er aus meinem timeout raus fliegt und dadurch wird dann nicht mehr richtig erkannt ...
also code auch nochmal hier :
Ausgabe:
wäre nett wenn mir wer helfen könnt
thx Kala
ich brauch ma noch n paar meinungen daher auch doppelpost über 2 foren:
wie ich in http://www.java-forum.org/de/topic55958_socket.html schon beschrieben hab:
ich habe anhand des links von slaterb mir die variante rausgesucht wie ich das netzwerk nach bestimmten rechnern absuch... leider ist es so das je mehr sockets ich auf und zu mach umso länger braucht er ... das is dann irgendwann so lang das er aus meinem timeout raus fliegt und dadurch wird dann nicht mehr richtig erkannt ...
also code auch nochmal hier :
Code:
package AVS3;
import java.io.*;
import java.net.*;
public class Ping2 {
public static long testConn(byte[] addr1, int port, int timeoutMs){
//pass in a byte array with the ipv4 address, the port & the max time out required
long start = -1; //default check value
long end = -1; //default check value
long total = -1; // default for bad connection
//make an unbound socket
Socket theSock = null;
try {
InetAddress addr = InetAddress.getByAddress(addr1);
System.out.println(addr);
SocketAddress sockaddr = new InetSocketAddress(addr,port);
//Create the socket with a timeout
//when a timeout occurs, we will get timout exp.
//also time our connection this gets very close to the real time
theSock = new Socket();
start = System.currentTimeMillis();
System.out.println("start:"+start);
theSock.connect(sockaddr, timeoutMs);
end = System.currentTimeMillis();
System.out.println("end:"+end);
} catch (UnknownHostException e) {
start = -1;
end = -1;
} catch (SocketTimeoutException e) {
start = -1;
end = -1;
} catch (IOException e) {
start = -1;
end = -1;
} finally {
if (theSock != null) {
try {
theSock.close();
} catch (IOException e) {}
}
if ((start != -1) && (end != -1)) {
total = end - start;
}
}
return total; //returns -1 if timeout
}
public static void main(String[] args) {
int port = 10000;
int timeout = 1000;
byte[] addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)1};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)5};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)6};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)7};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)8};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)9};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)10};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)11};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)12};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)5};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)6};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)7};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)8};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)9};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)10};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)11};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)12};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)20};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)21};
System.out.println(Ping2.testConn(addr, port, timeout));
addr = new byte[]{(byte)172,(byte)16,(byte)16,(byte)22};
System.out.println(Ping2.testConn(addr, port, timeout));
}
}
Ausgabe:
Code:
/172.16.16.1
start:1190027226125
-1
/172.16.16.5
start:1190027227140
-1
/172.16.16.6
start:1190027228140
-1
/172.16.16.7
start:1190027229140
-1
/172.16.16.8
start:1190027230140
-1
/172.16.16.9
start:1190027231140
-1
/172.16.16.10
start:1190027232140
-1
/172.16.16.11
start:1190027233156
-1
/172.16.16.12
start:1190027234156
-1
/172.16.16.20
start:1190027235156
end:1190027235156
0
/172.16.16.21
start:1190027235156
-1
/172.16.16.22
start:1190027236171
-1
/172.16.16.20
start:1190027237171
end:1190027237796
625
/172.16.16.20
start:1190027237796
end:1190027237796
0
/172.16.16.21
start:1190027237812
-1
/172.16.16.22
start:1190027238812
-1
/172.16.16.20
start:1190027239812
end:1190027239812
0
/172.16.16.21
start:1190027239828
-1
/172.16.16.22
start:1190027240828
-1
/172.16.16.20
start:1190027241828
end:1190027241828
0
/172.16.16.21
start:1190027241828
-1
/172.16.16.22
start:1190027242828
-1
/172.16.16.5
start:1190027243828
-1
/172.16.16.6
start:1190027244828
-1
/172.16.16.7
start:1190027245828
-1
/172.16.16.8
start:1190027246828
-1
/172.16.16.9
start:1190027247828
-1
/172.16.16.10
start:1190027248828
-1
/172.16.16.11
start:1190027249828
-1
/172.16.16.12
start:1190027250828
-1
/172.16.16.20
start:1190027251828
-1
/172.16.16.21
start:1190027252843
-1
/172.16.16.22
start:1190027253843
-1
/172.16.16.20
start:1190027254843
end:1190027254843
0
/172.16.16.20
start:1190027254843
end:1190027254843
0
/172.16.16.21
start:1190027254859
-1
/172.16.16.22
start:1190027255859
-1
/172.16.16.20
start:1190027256859
end:1190027256859
0
/172.16.16.21
start:1190027256859
-1
/172.16.16.22
start:1190027257859
-1
/172.16.16.20
start:1190027258859
-1
/172.16.16.21
start:1190027259859
-1
/172.16.16.22
start:1190027260859
-1
wäre nett wenn mir wer helfen könnt
thx Kala