python编写主机发现工具(ICMP)

"""
scapy发送icmp包,进行主机发现 ping
"""
from scapy.all import *
from optparse import OptionParser
from concurrent.futures import ThreadPoolExecutor

def scan_host(ip):
    pkt = IP()/ICMP(seq=2000)/b'hello world'
    pkt['IP'].dst = ip
    results = sr1(pkt,timeout=3,iface = IFACES.dev_from_index(8),verbose=0)
    if results:
        print('[+] host: %s is up'%ip)

if __name__ == "__main__":
    opt = OptionParser("usage: %prog -i ip or ips")
    opt.add_option("-i", '--IP', type="string", dest="ips", help="input ip or ips")
    opt.add_option("-t", '--threads', type="int", dest="threads", help="threads number")
    options, args = opt.parse_args()
    ips = options.ips
    if "-" in ips:
        start_ip = ips.split("-")[0]
        start_num = int(start_ip.split('.')[-1])
        end_num = int(ips.split("-")[1])
        thread_num = options.threads
        with ThreadPoolExecutor(max_workers=thread_num) as pool:
            for num in range(start_num,end_num+1):
                tmp = start_ip.split(".")
                ip = tmp[0]+"."+tmp[1]+"."+tmp[2]+"."+str(num)
                pool.submit(scan_host,ip)
    else:
        scan_host(ips)

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值