前言
服务器的相关知识曾经让我非常困惑。我相信还有很多的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('xFFxFFxFFxFFx69x6Ex66x6Fx73x74x72x69x6Ex67x0A 0') 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('xFFxFFxFFxFFx54x53x6Fx75x72x63x65x20x45x6Ex67x69x6Ex65x20x51x75x65x72x79x00') 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反恐精英服务器信息的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。