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

29 lines
663 B
Python
Raw Normal View History

2016-01-19 21:32:16 +00:00
from time import time
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:
def __init__(self, addr, challenge):
2016-01-19 21:32:16 +00:00
# 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