Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Email

62.4. POP Sniffer

# Author: neo chan
# Homepage: http://netkiller.8800.org

import socketserver,sys
import threading

class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):

	def setup(self):
		print(self.client_address[0], 'connected!')
		self.request.send(b'+OK Welcome to coremail Mail Pop3 Server \r\n')

	def handle(self):
    	# self.request is the TCP socket connected to the client
		while True:
			self.data = self.request.recv(1024).strip()
			if self.data == b'QUIT':
			if self.data == b'AUTH':
				self.request.send(b'-ERR Not support ntlm auth method\r\n')
			print("%s wrote: " % self.client_address[0])
			print (self.data)
			# just send back the same data, but upper-cased
			# self.request.send(self.data.upper())
			self.request.send(b'+OK 0 message(s) [0 byte(s)]\r\n')

	def finish(self):
		print( self.client_address[0], 'disconnected!')
		self.request.send(b'Goodbye! \r\n')

class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):

if __name__ == "__main__":
	HOST, PORT = "", 110

	# Create the server, binding to localhost on port 110
	# server = socketserver.TCPServer((HOST, PORT), MyTCPHandler)
	# server.serve_forever()

	# Activate the server; this will keep running until you
	# interrupt the program with Ctrl-C
		server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
		# Start a thread with the server -- that thread will then start one
		# more thread for each request
		server_thread = threading.Thread(target=server.serve_forever)
		# Exit the server thread when the main thread terminates
		# server_thread.setDaemon(True)
	except KeyboardInterrupt:
comments powered by Disqus