-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbwspeed_http.py
More file actions
47 lines (40 loc) · 1.17 KB
/
bwspeed_http.py
File metadata and controls
47 lines (40 loc) · 1.17 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
#!/usr/bin/env python
import sys
import time
import socket
from threading import Thread
host = '184.173.198.48'
port = 80
thread_count = 10
class Controller:
def __init__(self):
self.count_ref = []
def start(self):
for i in range(thread_count):
agent = Agent(self.count_ref)
agent.setDaemon(True)
agent.start()
print 'started %d threads' % (i + 1)
while True:
time.sleep(1)
line = 'connects/sec: %s' % len(self.count_ref)
self.count_ref[:] = []
sys.stdout.write(chr(0x08) * len(line))
sys.stdout.write(line)
class Agent(Thread):
def __init__(self, count_ref):
Thread.__init__(self)
self.count_ref = count_ref
def run(self):
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host, port))
s.shutdown(2)
s.close()
self.count_ref.append(1)
except:
print 'SOCKET ERROR\n'
if __name__ == '__main__':
controller = Controller()
controller.start()