Skip to content

Commit 2e25c3e

Browse files
author
duanhongyi
committed
add frequency
1 parent 7ec23b0 commit 2e25c3e

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

bin/icmp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def send_one_ping(my_socket, dest_addr, ID):
8888
my_socket.sendto(packet, (dest_addr, 1)) # Don't know about the 1
8989

9090

91-
def ping(dest_addr, timeout):
91+
def ping(dest_addr, timeout, frequency=3):
9292
"""
9393
Returns either the delay (in seconds) or none on timeout.
9494
"""
@@ -107,8 +107,9 @@ def ping(dest_addr, timeout):
107107

108108
my_ID = os.getpid() & 0xFFFF
109109

110-
send_one_ping(my_socket, dest_addr, my_ID)
111-
delay = receive_one_ping(my_socket, my_ID, timeout)
112-
110+
for _ in range(frequency):
111+
send_one_ping(my_socket, dest_addr, my_ID)
112+
delay = receive_one_ping(my_socket, my_ID, timeout)
113+
if delay: break
113114
my_socket.close()
114115
return delay

bin/sdns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def task(amapping_blacklist, ip_list):
6969
while True:
7070
for ip in ip_list:
7171
try:
72-
delay = ping(ip, 9)
72+
delay = ping(ip, 2)
7373
except socket.gaierror as e:
7474
delay = None
7575
if delay == None and ip not in amapping_blacklist:

0 commit comments

Comments
 (0)