Proxy.py

backup 2016.06.13 14:53
import socket
import os
import sys

class Server():
	def __init__(self,port):
		self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		self.s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
		self.s.bind(("",port))
		self.s.listen(10)

	def Connect(self):
		self.client, self.addr = self.s.accept()
		print "[*] %s is connected."%(self.addr[0])
		return self.client
			

	def FromUser(self):
		data = self.client.recv(65536)
		return data
		
class Client():
	def __init__(self,Host,Port):
		self.s = socket.socket()
		self.s.connect((Host,int(Port)))

	def FromServer(self):
		data = self.s.recv(65536)
		return data

if len(sys.argv) != 4:
	print "[*] USAGE : %s LocalPort RemoteHost RemotePort"%(sys.argv[0])
	exit(-1)

User = Server(int(sys.argv[1]))
while(1):
	User.Connect()
	pid = os.fork()
	if pid == 0:
		Server = Client(sys.argv[2],sys.argv[3])
		pid = os.fork()
		if pid == 0:
			while (1):
				try:
					data = Server.FromServer()
					User.client.send(data)
				except:
					pass
		else:
			while(1):
				try:
					data = User.FromUser()
					Server.s.send(data+"\r\n")
				except:
					pass
	else:
		continue

'backup' 카테고리의 다른 글

Proxy.py  (0) 2016.06.13
Pixiv Crawler  (0) 2016.06.02
Zip parser source  (0) 2016.03.15
PHP - unserialize  (0) 2015.08.18
profile  (0) 2015.02.06
ip-time n150ua  (0) 2014.11.25
Posted by Maid:: IzayoiSakuya