forked from majek/dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind_connect.py
75 lines (58 loc) · 1.58 KB
/
bind_connect.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import socket
import random
import time
import errno
a = []
try:
for i in range(1000):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('192.168.97.139', 0))
a.append(s)
except Exception, e:
print e
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("www.google.com", 80))
'''
addr = ('192.168.97.139', 1091)
print "port: %s" % (addr,)
if True:
x = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
x.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
x.bind(addr)
x.connect(("idea.popcount.org", 80))
for i in range(5):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
try:
s.connect(("idea.popcount.org", 80))
break
except socket.error, e:
if e.errno != errno.EADDRNOTAVAIL:
raise
else:
raise Exception("Unable to allocate connection")
print "waiting"
time.sleep(130)
'''
'''
HOSTS = ["idea.popcount.org", "www.wp.pl", "idea.popcount.org"]
addr = ('192.168.97.139', 1099) #random.randint(5000,6000)
print "port: %s" % (addr,)
sds = []
for host in HOSTS:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#s.bind(('0.0.0.0', port))
s.bind(addr)
#s.setblocking(False)
s.connect((host, 80))
sds.append( s )
for s in sds:
print s.getsockname(), s.getpeername()
s.send("GET /")
print "waiting"
while True:
time.sleep(130)
'''