- Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathserver_proxy_select.py
More file actions
Latest commit
46 lines (36 loc) · 984 Bytes
/
Copy pathserver_proxy_select.py
File metadata and controls
46 lines (36 loc) · 984 Bytes
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
importselect
importsocket
importsys
importurllib2
HOST=''
PORT=8888
backlog=5
size=1024
server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind ((HOST, PORT))
server.listen(backlog)
input= [server, sys.stdin]
running=1
defget_webpage(url):
result=urllib2.urlopen(url).read()
returnresult
whilerunning:
inputready, outputready, exceptready=select.select(input, [],[])
forsininputready:
ifs==server:
client, address=server.accept()
input.append(client)
elifs==sys.stdin:
junk=sys.stdin.readline()
running=0
else:
data=s.recv(size)
ifdata:
if"http://"indata:
url=data.strip()
data_to_client=get_webpage(url)
s.send(data_to_client)
else:
s.close()
input.remove(s)
server.close()