-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping.py
39 lines (30 loc) · 871 Bytes
/
ping.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
import threading
import Queue
import subprocess
import sys
class Ping(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self._queue = queue
def run(self):
result = []
while not self._queue.empty():
ip = self._queue.get()
result = subprocess.Popen('ping -n 2 %s'%ip,stdout=subprocess.PIPE)
data = result.stdout.read().decode('gbk')
if "TTL" in data:
print(ip)
def main():
threads = []
threads_count = 50
queue = Queue.Queue()
for i in range(1,255):
queue.put('106.75.137.' + str(i))
for i in range(threads_count):
threads.append(Ping(queue))
for i in threads:
i.start()
for i in threads:
i.join()
if __name__ == "__main__":
main()