mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
send fewer initial UDP packets and send more if successful reply
This commit is contained in:
parent
90fee8b568
commit
e21f523013
@ -29,15 +29,17 @@ 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 udpResult = udpPinger.ping(subject, max(1, (int)Math.ceil(count / 1.5)));
|
||||
if (udpResult.isAlive()) return udpResult;
|
||||
int udpCountInitialCount = max(1, count / 2);
|
||||
PingResult udpResult = udpPinger.ping(subject, udpCountInitialCount);
|
||||
if (udpResult.isAlive())
|
||||
return udpResult.merge(udpPinger.ping(subject, count - udpCountInitialCount));
|
||||
|
||||
// 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 {
|
||||
public void close() {
|
||||
udpPinger.close();
|
||||
tcpPinger.close();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user