zoukankan      html  css  js  c++  java
  • 超级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 '33[31m%s UP33[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'
  • 相关阅读:
    n的阶乘
    二叉树遍历
    二分查找练习
    字符串中最长回文序列求解
    复数集合
    AppCrawler自动化遍历使用详解(版本2.1.0 )(转)
    谷歌驱动下载链接
    谷歌浏览器插件
    Pycharm破解方法
    go学习链接
  • 原文地址:https://www.cnblogs.com/nul1/p/9901942.html
Copyright © 2011-2022 走看看