-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patholdproxy.py
More file actions
executable file
·61 lines (56 loc) · 1.64 KB
/
oldproxy.py
File metadata and controls
executable file
·61 lines (56 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
import os
import subprocess
import time
import socket
import sys
import mimetypes
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email import utils, encoders
from gevent import monkey
#monkey.patch_all()
var = {}
port = 8000
cache = {}
def main():
argv = sys.argv
var['root'] = "."
if len(argv) > 1:
var['root'] = argv[1]
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversocket.bind((socket.gethostname(), port))
print "Hostname:", socket.gethostbyname(socket.gethostname())
print "Connected on port", port
serversocket.listen(5)
while 1:
client, address = serversocket.accept()
client_data = client.recv(1024)
if '\r\n' in client_data:
key = tuple(client_data.split('\r\n')[0:2])
elif '\n' in client_data:
key = tuple(client_data.split('\n')[0:2])
else:
key = tuple(client_data.split('\r')[0:2])
if key in cache:
pass
print key
print key[1][6:].split(':')
full_host_string = key[1][6:]
if ":" in full_host_string:
host, host_port = tuple(split(':'))
else:
host = full_host_string
host_port = 80
sock = socket.socket()
sock.connect((host, host_port))
print "Connected to host."
host_data = sock.recv(1024)
print host_data
client.send(host_data)
client.close()
return ret
if __name__ == "__main__":
main()