Skip to content
Permalink
Browse files

Don't count things like DNS resolution in the ping

  • Loading branch information...
ShadowNinja committed Nov 20, 2014
1 parent a835362 commit a3424b80352b6414cb41ab6696a4a3051b2fc475
Showing with 6 additions and 5 deletions.
  1. +6 −5 server.py
@@ -135,19 +135,20 @@ def purgeOld():
# Returns ping time in seconds (up), False (down), or None (error).
def serverUp(address, port):
try:
start = time.time()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(3)
sock.connect((address, port))
buf = b"\x4f\x45\x74\x03\x00\x00\x00\x01"
sock.sendto(buf, (address, port))
data, addr = sock.recvfrom(1000)
sock.send(buf)
start = time.time()
data = sock.recv(1024)
end = time.time()
if not data:
return False
peer_id = data[12:14]
buf = b"\x4f\x45\x74\x03" + peer_id + b"\x00\x00\x03"
sock.sendto(buf, (address, port))
sock.send(buf)
sock.close()
end = time.time()
return end - start
except socket.timeout:
return False

0 comments on commit a3424b8

Please sign in to comment.
You can’t perform that action at this time.