forked from Mirrorlandia_minetest/minetest
Protocol Docs: Python check bump to Python 3
This commit is contained in:
parent
3c7e92049d
commit
23ea02c79c
@ -71,17 +71,19 @@ function check_if_minetestserver_up($host, $port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
- Here's a Python script for checking if a minetest server is up, confirmed working
|
- Here's a Python script for checking if a minetest server is up, confirmed working
|
||||||
#!/usr/bin/env python
|
|
||||||
|
#!/usr/bin/env python3
|
||||||
import sys, time, socket
|
import sys, time, socket
|
||||||
|
|
||||||
address = ""
|
address = ""
|
||||||
port = 30000
|
port = 30000
|
||||||
if len(sys.argv) <= 1:
|
if len(sys.argv) <= 1:
|
||||||
print("Usage: %s <address>" % sys.argv[0])
|
print("Usage: %s <address>" % sys.argv[0])
|
||||||
exit()
|
exit()
|
||||||
if ':' in sys.argv[1]:
|
if ":" in sys.argv[1]:
|
||||||
address = sys.argv[1].split(':')[0]
|
address = sys.argv[1].split(":")[0]
|
||||||
try:
|
try:
|
||||||
port = int(sys.argv[1].split(':')[1])
|
port = int(sys.argv[1].split(":")[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Please specify a valid port")
|
print("Please specify a valid port")
|
||||||
exit()
|
exit()
|
||||||
@ -92,17 +94,17 @@ try:
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sock.settimeout(2.0)
|
sock.settimeout(2.0)
|
||||||
buf = "\x4f\x45\x74\x03\x00\x00\x00\x01"
|
buf = b"\x4f\x45\x74\x03\x00\x00\x00\x01"
|
||||||
sock.sendto(buf, (address, port))
|
sock.sendto(buf, (address, port))
|
||||||
data, addr = sock.recvfrom(1000)
|
data, addr = sock.recvfrom(1000)
|
||||||
if data:
|
if data:
|
||||||
peer_id = data[12:14]
|
peer_id = data[12:14]
|
||||||
buf = "\x4f\x45\x74\x03" + peer_id + "\x00\x00\x03"
|
buf = b"\x4f\x45\x74\x03" + peer_id + b"\x00\x00\x03"
|
||||||
sock.sendto(buf, (address, port))
|
sock.sendto(buf, (address, port))
|
||||||
sock.close()
|
sock.close()
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print("%s is up (%0.5fms)" % (sys.argv[1],end-start))
|
print("%s is up (%0.5fms)" % (sys.argv[1], end - start))
|
||||||
else:
|
else:
|
||||||
print("%s seems to be down " % sys.argv[1])
|
print("%s seems to be down " % sys.argv[1])
|
||||||
except:
|
except Exception as err:
|
||||||
print("%s seems to be down " % sys.argv[1])
|
print("%s seems to be down (%s) " % (sys.argv[1], str(err)))
|
||||||
|
Loading…
Reference in New Issue
Block a user