mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
increase number of udp packets in combined pinger and display total number of packets for dead hosts in PacketLossFetcher
This commit is contained in:
parent
643a4e4705
commit
ff88ded1fe
@ -30,12 +30,12 @@ public class CombinedUnprivilegedPinger implements Pinger {
|
||||
|
||||
public PingResult ping(ScanningSubject subject, int count) throws IOException {
|
||||
// try UDP first - it should be more reliable in general
|
||||
PingResult result = udpPinger.ping(subject, max(1, count / 2));
|
||||
if (!result.isAlive()) {
|
||||
// fallback to TCP - it may detect some hosts UDP cannot
|
||||
result = tcpPinger.ping(subject, count);
|
||||
}
|
||||
return result;
|
||||
PingResult udpResult = udpPinger.ping(subject, max(1, (int)Math.ceil(count / 1.5)));
|
||||
if (udpResult.isAlive()) return udpResult;
|
||||
|
||||
// fallback to TCP - it may detect some hosts UDP cannot
|
||||
PingResult tcpResult = tcpPinger.ping(subject, count);
|
||||
return tcpResult.merge(udpResult);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
|
||||
@ -53,19 +53,18 @@ public class PingResult {
|
||||
}
|
||||
|
||||
public int getPacketLoss() {
|
||||
return (int)(packetCount - replyCount);
|
||||
return packetCount - replyCount;
|
||||
}
|
||||
|
||||
public int getPacketLossPercent() {
|
||||
if(this.replyCount>0){
|
||||
return (int) ((this.getPacketLoss() * 100) / packetCount);
|
||||
}else{
|
||||
if (replyCount > 0)
|
||||
return (this.getPacketLoss() * 100) / packetCount;
|
||||
else
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPacketCount() {
|
||||
return (int)(packetCount);
|
||||
return packetCount;
|
||||
}
|
||||
|
||||
public int getReplyCount() {
|
||||
@ -87,4 +86,10 @@ public class PingResult {
|
||||
public boolean isTimeoutAdaptationAllowed() {
|
||||
return timeoutAdaptationAllowed;
|
||||
}
|
||||
|
||||
PingResult merge(PingResult result) {
|
||||
this.packetCount += result.packetCount;
|
||||
this.replyCount += result.replyCount;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,6 +30,6 @@ public class PacketLossFetcher extends PingFetcher {
|
||||
PingResult result = executePing(subject);
|
||||
subject.setResultType(result.isAlive() ? ALIVE : DEAD);
|
||||
|
||||
return result.getPacketLoss() + "/" + result.getPacketCount() + " ("+ result.getPacketLossPercent() + "%)";
|
||||
return result.getPacketLoss() + "/" + result.getPacketCount() + " (" + result.getPacketLossPercent() + "%)";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user