超級ping(多線程版)


 

發現學校公共wifi的ip段是10.1.0-255.0-255段的,還是之前的思路批量ping一波。

其實可以使用nmap的。但是腳本寫都寫了。是吧。你懂的。

 1 #!/usr/bin/env python
 2 #encoding:utf-8
 3 
 4 from threading import Thread  
 5 import subprocess  
 6 from Queue import Queue  
 7 
 8 num_threads=10
 9 ips = []
10 for a in range(256):
11     for b in range(256):
12         ip = "10.1."+str(a)+"."+str(b)
13         ips.append(ip)
14 
15 q = Queue()
16 def pingme(i,queue):
17     while True:  
18         ip=queue.get()
19         ret=subprocess.call('ping -c 1 %s' % ip,shell=True,stdout=open('/dev/null','w'),stderr=subprocess.STDOUT)  
20         if ret==0:  
21             print '\033[31m%s UP\033[0m' %ip  
22         elif ret==1:
23             print '%s is down...'%ip  
24         queue.task_done()  
25 
26 #start num_threads threads  
27 for i in range(num_threads):  
28     t=Thread(target=pingme,args=(i,q))  
29     t.setDaemon(True)  
30     t.start()
31 
32 for ip in ips: 
33     q.put(ip)
34 q.join();
35 print 'Done'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM