目的是通过逆向police。实现一个thief,可以与police进行通信
实际上就是一个RSA加密通信的样例,我们通过自己编写client和服务端来实现上面的thief和police的功能..
要通信。这们这次先通过python写出能够进行网络连接的client与服务端..
服务端代码
#!/usr/bin/env python import SocketServer from time import ctime HOST = '127.0.0.1' PORT = 2012 ADDR = (HOST, PORT) class MyRequestHandler(SocketServer.BaseRequestHandler): def handle(self): print '...connected from...', self.client_address while True: self.request.sendall('[%s] %s' % (ctime(),self.request.recv(1024))) tcpServ = SocketServer.ThreadingTCPServer(ADDR, MyRequestHandler) print 'waiting for connection...' tcpServ.serve_forever()
client代码:
#!/usr/bin/env python from socket import * HOST = '127.0.0.1' PORT = 2012 BUFSIZ = 1024 ADDR = (HOST, PORT) tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect(ADDR) while True: data = raw_input('>>>>>>>>>>>>') if not data: break tcpCliSock.send('%s\r\n' % data) data = tcpCliSock.recv(BUFSIZ) if not data: break print data.strip() #tcpCliSock.close()
这段代码可參考《python核心编程》
假设报python errno 10053错误,请确认下client的连接代码一定要在循环外
也就是
tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect(ADDR)要在while True的外面..
下次解决RSA加密的问题