File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Python-
2
+ Python的小项目记录我成长的点滴
3
+ 扫描ç段存活主机
4
+
5
+ import threading
6
+ import Queue
7
+ import subprocess
8
+ import sys
9
+
10
+ class Ping(threading.Thread):
11
+ def __ init__ (self,queue):
12
+ threading.Thread.__ init__ (self)
13
+ self._ queue = queue
14
+
15
+ def run(self):
16
+ result = []
17
+ while not self._queue.empty():
18
+ ip = self._queue.get()
19
+ result = subprocess.Popen('ping -n 2 %s'%ip,stdout=subprocess.PIPE)
20
+ data = result.stdout.read().decode('gbk')
21
+ if "TTL" in data:
22
+ print(ip)
23
+
24
+
25
+ def main():
26
+ threads = [ ]
27
+ threads_count = 50
28
+ queue = Queue.Queue()
29
+
30
+ for i in range(1,255):
31
+ queue.put('106.75.137.' + str(i))
32
+
33
+ for i in range(threads_count):
34
+ threads.append(Ping(queue))
35
+
36
+ for i in threads:
37
+ i.start()
38
+
39
+ for i in threads:
40
+ i.join()
41
+
42
+ if __ name__ == "__ main__ ":
43
+ main()
You can’t perform that action at this time.
0 commit comments