How to query the server information of CS counter elite under python
- 2020-05-19 05:11:25
- OfStack
preface
Server knowledge used to confuse me. I'm sure there are plenty of other Python developers who have had a similar experience. This paper mainly introduces how to query the server information of CS counter elite under python, if you need, you can refer to the study.
CS counter strike version 1.5 sample code
#!/bin/env python
import urllib2, base64, sys, getopt
import re
import socket
def Usage ():
print "Usage: hlds.py -h 127.0.0.1 -p 27015"
sys.exit(2)
def main ():
# Default values
host = "localhost"
port = ""
if len(sys.argv) < 1:
Usage()
try:
opts, args = getopt.getopt(sys.argv[1:], "h:p:a:")
except getopt.GetoptError:
Usage()
# Assign parameters as variables
for opt, arg in opts :
if opt == "-h" :
host = arg
if opt == "-p" :
port = arg
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port = int(port)
sock.settimeout(10)
sock.connect((host, port))
sock.send('\xFF\xFF\xFF\xFF\x69\x6E\x66\x6F\x73\x74\x72\x69\x6E\x67\x0A\00')
request=sock.recv(1400)
sock.close()
server_info=request.replace('\xFF', '')
buffer = re.findall(r'\d+', server_info)
print buffer[6]
if __name__ == "__main__":
main()
CS counter strike version 1.6 sample code
#!/bin/env python
import urllib2, base64, sys, getopt
import re
import socket
def Usage ():
print "Usage: hlds.py -h 127.0.0.1 -p 27015"
sys.exit(2)
def main ():
# Default values
host = "localhost"
port = ""
if len(sys.argv) < 1:
Usage()
try:
opts, args = getopt.getopt(sys.argv[1:], "h:p:a:")
except getopt.GetoptError:
Usage()
# Assign parameters as variables
for opt, arg in opts :
if opt == "-h" :
host = arg
if opt == "-p" :
port = arg
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port = int(port)
sock.settimeout(10)
sock.connect((host, port))
sock.send('\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00')
request=sock.recv(1400)
sock.close()
#server_info=request.replace('\xFF', '')
print request
#buffer = re.findall(r'\d+', server_info)
#print buffer[6]
#print buffer
if __name__ == "__main__":
main()
conclusion
The above is about python under the inquiry CS counter elite server information all content, hope the content of this article to your study or work can bring 1 certain help, if you have any questions can leave a message to communicate.