-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathworkers.py
More file actions
69 lines (54 loc) · 1.63 KB
/
workers.py
File metadata and controls
69 lines (54 loc) · 1.63 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
62
63
64
65
66
67
68
69
import httplib
import threading
class logWorker(threading.Thread):
def __init__(self, addr, rt):
self.addrs = addr
self.status = 1
self.connects = 0
self.rt = rt
threading.Thread.__init__(self)
self.setDaemon(True)
def make_connection(self):
raise NotImplementedError()
def close_connection(self):
raise NotImplementedError()
def send_data(self,ad):
raise NotImplementedError()
def good(self):
raise NotImplementedError()
def bad(self):
raise NotImplementedError()
def run(self):
self.make_connection()
for ad in self.addrs:
try:
self.send_data(ad)
self.good()
except:
self.bad()
self.close_connection()
self.close_connection()
class DefaultWorker(logWorker):
def __init__(self, addr, return_type, host, ip, port):
self.HOST = host
self.PORT = port
if ip:
self.IP = ip
else:
self.IP = host
self.headers = {"Host": host, "Keep-Alive": 300, "Connection": "keep-alive"}
logWorker.__init__(self, addr, return_type)
def make_connection(self):
self.connects += 1
self.s = httplib.HTTPConnection(self.IP, self.PORT)
def close_connection(self):
self.s.close()
def send_data(self,ad):
self.s.request("GET", ad, None, self.headers)
response = self.s.getresponse()
response.read()
def good(self):
self.rt['GOOD'] += 1
def bad(self):
self.rt['BAD'] += 1
self.status = 0