Answer the question
In order to leave comments, you need to log in
How to inflate Source-Query in Python 3+?
Hello everyone, help me inflate Source-Query. I want to poll the CS 1.6 server I
wrote a couple of lines, but it doesn't even respond. The firewall is disabled on the server.
import socket
IP = '195.62.53.149'
PORT = 27015
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((IP, PORT))
sock.send('TSource Engine Query'.encode('utf-8'))
sock.settimeout(120)
text = sock.recv(1024)
print('res ->' + text)
Answer the question
In order to leave comments, you need to log in
Your code is working, except for the last line, where you add bytes to the line. You don't get an answer because the request is made incorrectly, but this is no longer a question of the programming language or sockets, but of the format of requests and responses. The request must start with four 'FF' bytes.
import socket
IP = '195.62.53.149'
PORT = 27015
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((IP, PORT))
sock.send(b'\xff\xff\xff\xffTSource Engine Query')
sock.settimeout(120)
text = sock.recv(1024)
print(b'res ->' + text)
> python cs_udp.py
b'recv -> \xff\xff\xff\xffI0Euro-Cs.Ru | Public | 1000FPS\x00de_dust2_2x2\x00cstrike\x00Counter-Strike\x00\n\x00\x03\x14\x00dl\x00\x011.1.2.7/Stdio\x00\x80\x87i'
import valve.source.a2s
SERVER_ADDRESS = ('195.62.53.149', 27015)
with valve.source.a2s.ServerQuerier(SERVER_ADDRESS) as server:
info = server.info()
players = server.players()
print("{player_count}/{max_players} {server_name}".format(**info))
for player in sorted(players["players"],
key=lambda p: p["score"], reverse=True):
print("{score} {name}".format(**player))
> python udp_client.py
4/20 Euro-Cs.Ru | Public | 1000FPS
39 1UP|mam?a
31 zakeman4
16 Cosmodesant
0 (А.У.Е.ШПАНА) хуй
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question