1
0
Fork 0
mirror of https://github.com/de2tla2f/pymaster.git synced 2024-11-23 11:31:28 +00:00
pymaster/server_entry.py

29 lines
663 B
Python

from time import time
from struct import pack
import ipaddress
class ServerEntry:
def __init__(self, addr, challenge):
# Address
self.addr = addr
# Shortcuts for generating query
self.queryAddr = b''
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))
self.queryAddr += pack('!H', int(addr[1]))
# 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