_昏鸦

导航

 

0x00.前言

  学了一下python的多线程,threading模块

  感觉挺有意思的,随便练手写了一个很粗陋的windows下多线程扫在线ip的脚本

  脚本没什么技术含量,纯粹练手,扫一趟192的局域网要花个5分多钟...主要是因为直接用的python调用system命令去ping...

0x01.代码

# Author: 昏鸦

import os
import threading

def scan(lis):
    ip = "192.168.1.{}"
    for i in lis:
        res = ''.join(os.popen('ping -n 2 ' + ip.format(i)).readlines())
        pattern = "([\d]+)% 丢失"
        drop = re.search(pattern,res).group(1)
        if '无法访问' in res:
            continue
        else:
            if int(drop)< 51:
                print(ip.format(i))
            else:
                continue

if __name__ == '__main__':
    threads = []
    for i in range(5):
        t = threading.Thread(target=scan,args=(list(range(i*51,i*51+51)),))
        threads.append(t)
    for t in threads:
        t.start()
    for t in threads:
        t.join()

 

posted on 2018-12-13 20:46  _昏鸦  阅读(177)  评论(0编辑  收藏  举报