2016-01-19 21:32:16 +00:00
|
|
|
from time import time
|
2016-01-20 23:24:37 +00:00
|
|
|
from struct import pack
|
2016-01-19 21:32:16 +00:00
|
|
|
|
2023-12-26 17:15:10 +00:00
|
|
|
import ipaddress
|
|
|
|
|
2016-01-19 21:32:16 +00:00
|
|
|
class ServerEntry:
|
2022-12-07 19:03:24 +00:00
|
|
|
|
2024-01-09 01:27:45 +00:00
|
|
|
def __init__(self, addr, challenge):
|
2016-01-19 21:32:16 +00:00
|
|
|
|
2024-01-09 01:27:45 +00:00
|
|
|
# Address
|
|
|
|
self.addr = addr
|
|
|
|
# Shortcuts for generating query
|
|
|
|
self.queryAddr = b''
|
2022-12-07 19:03:24 +00:00
|
|
|
|
2024-01-09 01:27:45 +00:00
|
|
|
if ':' in addr[0]:
|
|
|
|
self.queryAddr += ipaddress.ip_address(addr[0]).packed
|
|
|
|
else:
|
|
|
|
for i in addr[0].split('.'):
|
|
|
|
self.queryAddr += pack('!B', int(i))
|
2022-12-07 19:03:24 +00:00
|
|
|
|
2024-01-09 01:27:45 +00:00
|
|
|
self.queryAddr += pack('!H', int(addr[1]))
|
2022-12-07 19:03:24 +00:00
|
|
|
|
2024-01-09 01:27:45 +00:00
|
|
|
# Random number that server must return
|
|
|
|
self.challenge = challenge
|
|
|
|
self.sentChallengeAt = time()
|
|
|
|
|
|
|
|
# Remove server after this time.
|
|
|
|
# This maybe not instant
|
|
|
|
self.die = self.sentChallengeAt + 600
|