python下如何查询cs反恐精英的服务器信息

前言

服务器的相关知识曾经让我非常困惑。我相信还有很多的python开发者和我有着类似的遭遇。本文主要介绍了python下如何查询cs反恐精英的服务器信息,有需要的可以参考学习。

cs反恐精英1.5版本示例代码

#!/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反恐精英1.6版本示例代码

#!/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()

更多python下如何查询cs反恐精英的服务器信息相关文章请关注php中文网!

Posted in 未分类

发表评论