How to query CS Counter-Strike server information under Python

Source: Internet
Author: User
Preface

The knowledge of the server has made me very confused. I believe there are a lot of Python developers and I have a similar experience. This article mainly introduces how to query CS Counter-Strike server information under Python, there is a need to refer to learning.

CS Counter Strike 1.5 version sample code

#!/bin/env python import urllib2, base64, SYS, getoptimport reimport 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.arg V) < 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":      hos t = arg    if opt = = "-P":      port = arg   sock = Socket.socket (socket.af_inet, socket. SOCK_DGRAM)  port = Int (port)  sock.settimeout (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 1.6 version sample code

#!/bin/env python import urllib2, base64, SYS, getoptimport reimport 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.arg V) < 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":      hos t = arg    if opt = = "-P":      port = arg   sock = Socket.socket (socket.af_inet, socket. SOCK_DGRAM)  port = Int (port)  sock.settimeout (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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.