Skip to content

Commit cbaae17

Browse files
committed
Merge pull request #2 from dfmogk/master
Added Client IP
2 parents 8233cf1 + 2a3b8e6 commit cbaae17

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

proxy.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
BACKLOG = 50 # how many pending connections queue will hold
1313
MAX_DATA_RECV = 999999 # max number of bytes we receive at once
1414
DEBUG = True # set to True to see the debug msgs
15-
BLOCKED = [] # just an example. Remove with [""] for no blocking at all.
15+
BLOCKED = [] # just an example. Remove with [""] for no blocking at all.
1616

1717
#**************************************
1818
#********* MAIN PROGRAM ***************
@@ -21,14 +21,15 @@ def main():
2121

2222
# check the length of command running
2323
if (len(sys.argv)<2):
24-
print "usage: proxy <port>"
25-
return sys.stdout
24+
print "No port given, using :8080 (http-alt)"
25+
port = 8080
26+
else:
27+
port = int(sys.argv[1]) # port from argument
2628

2729
# host and port info.
2830
host = '' # blank for localhost
29-
port = int(sys.argv[1]) # port from argument
3031

31-
print "Proxy Server Running on ",host,":",sys.argv[1]
32+
print "Proxy Server Running on ",host,":",port
3233

3334
try:
3435
# create a socket
@@ -56,6 +57,15 @@ def main():
5657
s.close()
5758
#************** END MAIN PROGRAM ***************
5859

60+
def printout(type,request,address):
61+
if "Block" in type or "Blacklist" in type:
62+
colornum = 91
63+
elif "Request" in type:
64+
colornum = 92
65+
elif "Reset" in type:
66+
colornum = 93
67+
68+
print "\033[",colornum,"m",address[0],"\t",type,"\t",request,"\033[0m"
5969

6070
#*******************************************
6171
#********* PROXY_THREAD FUNC ***************
@@ -74,10 +84,12 @@ def proxy_thread(conn, client_addr):
7484

7585
for i in range(0,len(BLOCKED)):
7686
if BLOCKED[i] in url:
77-
print "\033[91mBlocked: ",first_line,"\033[0m"
87+
printout("Blacklisted",first_line,client_addr)
88+
conn.close()
7889
sys.exit(1)
7990

80-
print "\033[92mRequest: ",first_line,"\033[0m"
91+
92+
printout("Request",first_line,client_addr)
8193
# print "URL:",url
8294
# print
8395

@@ -126,7 +138,7 @@ def proxy_thread(conn, client_addr):
126138
s.close()
127139
if conn:
128140
conn.close()
129-
print "\033[93mPeer Reset:",first_line,"\033[0m"
141+
printout("Peer Reset",first_line,client_addr)
130142
sys.exit(1)
131143
#********** END PROXY_THREAD ***********
132144

0 commit comments

Comments
 (0)