mirror of
https://github.com/Dinnerbone/mcstatus.git
synced 2026-04-06 03:51:23 +08:00
Merge pull request #26 from shoghicp/master
Resolve DNS before sending packets
This commit is contained in:
@@ -62,9 +62,17 @@ class MinecraftServer:
|
||||
|
||||
def query(self, retries=3):
|
||||
exception = None
|
||||
host = self.host
|
||||
try:
|
||||
answers = dns.resolver.query(host, "A")
|
||||
if len(answers):
|
||||
answer = answers[0]
|
||||
host = str(answer).rstrip(".")
|
||||
except Exception as e:
|
||||
pass
|
||||
for attempt in range(retries):
|
||||
try:
|
||||
connection = UDPSocketConnection((self.host, self.port))
|
||||
connection = UDPSocketConnection((host, self.port))
|
||||
querier = ServerQuerier(connection)
|
||||
querier.handshake()
|
||||
return querier.read_query()
|
||||
|
||||
Reference in New Issue
Block a user