[TOC] ## 以struct.pack发送(用于抓包工具抓取到的数据) ``` import socket import time import struct a=[0x00, 0x00, 0x01, 0x16, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x63, 0x68, 0x65, 0x6e, 0x70, 0x6a, 0x20, 0x61, 0x69, 0x70, 0x75, 0x20, 0x31, 0x20, 0x4b, 0x54, 0x74, 0x69, 0x56, 0x32, 0x41, 0x2b, 0x4d, 0x67, 0x79, 0x79, 0x51, 0x4e, 0x4c, 0x59, 0x43, 0x6c, 0x46, 0x39, 0x67, 0x77, 0x3d, 0x3d, 0x20, 0x32, 0x20, 0x32, 0x30, 0x34, 0x38, 0x20, 0x35, 0x2e, 0x32, 0x2e, 0x36, 0x31, 0x20, 0x31, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x76, 0x65, 0x72, 0x3a, 0x35, 0x2e, 0x32, 0x2e, 0x36, 0x31, 0x0a, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x0a, 0x6d, 0x61, 0x63, 0x61, 0x64, 0x64, 0x72, 0x3a, 0x37, 0x34, 0x2d, 0x44, 0x34, 0x2d, 0x33, 0x35, 0x2d, 0x44, 0x44, 0x2d, 0x41, 0x44, 0x2d, 0x46, 0x37, 0x2c, 0x42, 0x43, 0x2d, 0x39, 0x44, 0x2d, 0x41, 0x35, 0x2d, 0x37, 0x30, 0x2d, 0x32, 0x37, 0x2d, 0x41, 0x38, 0x2c, 0x30, 0x30, 0x2d, 0x35, 0x30, 0x2d, 0x35, 0x36, 0x2d, 0x43, 0x30, 0x2d, 0x30, 0x30, 0x2d, 0x30, 0x38, 0x2c, 0x37, 0x45, 0x2d, 0x31, 0x35, 0x2d, 0x35, 0x42, 0x2d, 0x37, 0x45, 0x2d, 0x41, 0x42, 0x2d, 0x38, 0x35, 0x2c, 0x30, 0x30, 0x2d, 0x31, 0x35, 0x2d, 0x35, 0x44, 0x2d, 0x32, 0x46, 0x2d, 0x39, 0x31, 0x2d, 0x30, 0x30, 0x2c, 0x30, 0x30, 0x2d, 0x46, 0x46, 0x2d, 0x37, 0x32, 0x2d, 0x38, 0x36, 0x2d, 0x30, 0x32, 0x2d, 0x44, 0x37, 0x2c, 0x30, 0x30, 0x2d, 0x46, 0x46, 0x2d, 0x43, 0x32, 0x2d, 0x38, 0x35, 0x2d, 0x30, 0x38, 0x2d, 0x34, 0x32, 0x0a, 0x6f, 0x70, 0x64, 0x61, 0x74, 0x61, 0x3a, 0x0a, 0x6f, 0x70, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x0a, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x3a, 0x31, 0x0a, 0x73, 0x6d, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x3a, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3a, 0x30, 0x0a, 0x0a ] sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect(('192.168.0.91', 6661)) time.sleep(2) date = struct.pack("%dB" % (len(a)), *a) sock.send(date) print(sock.recv(1024)) sock.close() ''' b'\x00\x00\x07\xa5\x00\x00\x00\x01\xaf*\x00\x08\x00\x00\x00\x00512 5DA295C5-149B-3623-953D-BBBE129ABC43 chenpj \xe9\x99\x88\x ... ''' ``` ## 以16进制转发 ``` sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect(('192.168.0.91', 6661)) time.sleep(2) date = struct.pack("%dB" % (len(a)), *a) //sock.send('\x00\x00\x01\x16\x00\x00\x00\x01\x01\x01\x00\x08\x00\x00\x00\x00\x63\x68\x65\x6e\x70\x6a\x20\x61\x69\x70\x75\x20\x31\x20\x4b\x54\x74\x69\x56\x32\x41\x2b\x4d\x67\x79\x79\x51\x4e\x4c\x59\x43\x6c\x46\x39\x67\x77\x3d\x3d\x20\x32\x20\x32\x30\x34\x38\x20\x35\x2e\x32\x2e\x36\x31\x20\x31\x0a\x63\x6c\x69\x65\x6e\x74\x76\x65\x72\x3a\x35\x2e\x32\x2e\x36\x31\x0a\x68\x6f\x73\x74\x6e\x61\x6d\x65\x3a\x0a\x6d\x61\x63\x61\x64\x64\x72\x3a\x37\x34\x2d\x44\x34\x2d\x33\x35\x2d\x44\x44\x2d\x41\x44\x2d\x46\x37\x2c\x42\x43\x2d\x39\x44\x2d\x41\x35\x2d\x37\x30\x2d\x32\x37\x2d\x41\x38\x2c\x30\x30\x2d\x35\x30\x2d\x35\x36\x2d\x43\x30\x2d\x30\x30\x2d\x30\x38\x2c\x37\x45\x2d\x31\x35\x2d\x35\x42\x2d\x37\x45\x2d\x41\x42\x2d\x38\x35\x2c\x30\x30\x2d\x31\x35\x2d\x35\x44\x2d\x32\x46\x2d\x39\x31\x2d\x30\x30\x2c\x30\x30\x2d\x46\x46\x2d\x37\x32\x2d\x38\x36\x2d\x30\x32\x2d\x44\x37\x2c\x30\x30\x2d\x46\x46\x2d\x43\x32\x2d\x38\x35\x2d\x30\x38\x2d\x34\x32\x0a\x6f\x70\x64\x61\x74\x61\x3a\x0a\x6f\x70\x74\x79\x70\x65\x3a\x0a\x70\x6c\x61\x74\x66\x6f\x72\x6d\x3a\x31\x0a\x73\x6d\x73\x63\x6f\x64\x65\x3a\x0a\x73\x74\x61\x74\x75\x73\x3a\x30\x0a\x0a'.encode()) //等效 //sock.send(b"\x00\x00\x01\x16\x00\x00\x00\x01\x01\x01\x00\x08\x00\x00\x00\x00\x63\x68\x65\x6e\x70\x6a\x20\x61\x69\x70\x75\x20\x31\x20\x4b\x54\x74\x69\x56\x32\x41\x2b\x4d\x67\x79\x79\x51\x4e\x4c\x59\x43\x6c\x46\x39\x67\x77\x3d\x3d\x20\x32\x20\x32\x30\x34\x38\x20\x35\x2e\x32\x2e\x36\x31\x20\x31\x0a\x63\x6c\x69\x65\x6e\x74\x76\x65\x72\x3a\x35\x2e\x32\x2e\x36\x31\x0a\x68\x6f\x73\x74\x6e\x61\x6d\x65\x3a\x0a\x6d\x61\x63\x61\x64\x64\x72\x3a\x37\x34\x2d\x44\x34\x2d\x33\x35\x2d\x44\x44\x2d\x41\x44\x2d\x46\x37\x2c\x42\x43\x2d\x39\x44\x2d\x41\x35\x2d\x37\x30\x2d\x32\x37\x2d\x41\x38\x2c\x30\x30\x2d\x35\x30\x2d\x35\x36\x2d\x43\x30\x2d\x30\x30\x2d\x30\x38\x2c\x37\x45\x2d\x31\x35\x2d\x35\x42\x2d\x37\x45\x2d\x41\x42\x2d\x38\x35\x2c\x30\x30\x2d\x31\x35\x2d\x35\x44\x2d\x32\x46\x2d\x39\x31\x2d\x30\x30\x2c\x30\x30\x2d\x46\x46\x2d\x37\x32\x2d\x38\x36\x2d\x30\x32\x2d\x44\x37\x2c\x30\x30\x2d\x46\x46\x2d\x43\x32\x2d\x38\x35\x2d\x30\x38\x2d\x34\x32\x0a\x6f\x70\x64\x61\x74\x61\x3a\x0a\x6f\x70\x74\x79\x70\x65\x3a\x0a\x70\x6c\x61\x74\x66\x6f\x72\x6d\x3a\x31\x0a\x73\x6d\x73\x63\x6f\x64\x65\x3a\x0a\x73\x74\x61\x74\x75\x73\x3a\x30\x0a\x0a") print(sock.recv(1024)) sock.close() ```