import socket target_host = "127.0.0.1" target_port = 9999 client = socket.socket(socket.AF_INET,socket.SOCK_STREAM) client.connect((target_host,target_port)) client.send("GET / HTTP/1.1\r\nHost:baidu.com\r\n\r\n") response = client.recv(4096) print response client.close()
这个是客户端口:
import socket import threading bind_ip = "0.0.0.0" bind_port = 9999 server = socket.socket(socket.AF_INET,socket.SOCK_STREAM) server.bind((bind_ip,bind_port)) server.listen(5) print "[*] listen on %s:%d" % (bind_ip,bind_port) def handle_client(client_socket): request = client_socket.recv(1024) print "[*] Received %s" % request client_socket.send("OK") client_socket.close() while True: client,addr = server.accept() print "[*] Accepted connection from: %s:%d" % (addr[0],addr[1]) client_handler = threading.Thread(target=handle_client,args=(client,)) client_handler.start()
这个是服务端口:
这个是运行的结果。
怎么样,我厉害吧,哈哈!
时间: 2024-09-29 23:02:47