refactored inet scanner
This commit is contained in:
parent
1e5e114300
commit
e15b633601
1 changed files with 16 additions and 10 deletions
|
|
@ -39,13 +39,7 @@ public class InetScanner {
|
||||||
for (int i = 1; i < 255 && !canceled; i++) {
|
for (int i = 1; i < 255 && !canceled; i++) {
|
||||||
try {
|
try {
|
||||||
String targetIp = netAddr+i;
|
String targetIp = netAddr+i;
|
||||||
exec.exec(platformPingCmd(targetIp));
|
boolean online = isReachable(InetAddress.getByName(targetIp));
|
||||||
|
|
||||||
boolean online = false;
|
|
||||||
for (String line; (line=exec.readLine()) != null;) {
|
|
||||||
if (platformPingCheck(line))
|
|
||||||
online = true;
|
|
||||||
}
|
|
||||||
if (online && listener != null)
|
if (online && listener != null)
|
||||||
listener.foundInetAddress(InetAddress.getByName(targetIp));
|
listener.foundInetAddress(InetAddress.getByName(targetIp));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
@ -74,12 +68,24 @@ public class InetScanner {
|
||||||
public static boolean isReachable(InetAddress ip){
|
public static boolean isReachable(InetAddress ip){
|
||||||
String[] output = OSAbstractionLayer.exec(platformPingCmd(ip.getHostAddress()));
|
String[] output = OSAbstractionLayer.exec(platformPingCmd(ip.getHostAddress()));
|
||||||
|
|
||||||
boolean online = false;
|
|
||||||
for (String line : output) {
|
for (String line : output) {
|
||||||
if (platformPingCheck(line))
|
if (platformPingCheck(line))
|
||||||
online = true;
|
return true;
|
||||||
}
|
}
|
||||||
return online;
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Will check if the given IP is reachable (Pingable).
|
||||||
|
* This method is faster if multiple pings are needed as a MultiCommandExecutor can be provided.
|
||||||
|
*/
|
||||||
|
public static boolean isReachable(InetAddress ip, MultiCommandExecutor exec) throws IOException {
|
||||||
|
exec.exec(platformPingCmd(ip.getHostAddress()));
|
||||||
|
|
||||||
|
for (String line; (line=exec.readLine()) != null;) {
|
||||||
|
if (platformPingCheck(line))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue