-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicServerInfo.py
More file actions
56 lines (42 loc) · 1.8 KB
/
Copy pathbasicServerInfo.py
File metadata and controls
56 lines (42 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import socket
import re
def separar_texto(texto):
palabras = re.findall(r'\\([^\\]+)', texto)
return {i+1: palabra for i, palabra in enumerate(palabras)}
def send_source_query(server_address, server_port, output_file):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
message = bytearray([
0xFF, 0xFF, 0xFF, 0xFF,
ord('T'), ord('S'), ord('o'), ord('u'),
ord('r'), ord('c'), ord('e'), ord(' '),
ord('E'), ord('n'), ord('g'), ord('i'),
ord('n'), ord('e'), ord(' '), ord('Q'),
ord('u'), ord('e'), ord('r'), ord('y'), 0x00
])
# print("Enviando mensaje:", message)
sock.sendto(message, (server_address, server_port))
response, _ = sock.recvfrom(1024)
with open(output_file, 'w') as file:
# textoServer = ("{}\n".format(response))
textoServer = ("{}".format(response))
texto = textoServer
palabras = separar_texto(texto)
for i, palabra in palabras.items():
if i == 5:
palabra = palabra.replace("x00", "")
print("Nombre:", palabra)
elif i == 6:
palabra = palabra.replace("x00", "")
print("Mapa:", palabra)
elif i == 10:
palabra = palabra.replace("x", "")
print("Número de jugadores:", palabra)
sock.close()
except Exception as e:
print("Error:", e)
if __name__ == "__main__":
server_address = "45.32.170.143"
server_port = 27015
output_file = "output.txt"
send_source_query(server_address, server_port, output_file)