码迷,mamicode.com
首页 > 其他好文 > 详细

00012 扫描局域网

时间:2019-11-02 10:17:19      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:ESS   col   inpu   app   inter   interrupt   imp   exiting   pre   

import sys
from scapy.all import Ether, ARP, srp

def main():
    _range = input("Enter the Target Range: ")
    _interface = input("Enter the network interface: ")
    ip, ntBits = _range.split(/)
    ip_addresses = []
    st_bit = ip.split(.)[3:4][0]   #Since it‘s an IPv4
    for n in range(1, int(ntBits)+1):
        eval_ip = ".".join( ip.split(.)[:-1] ) + . + str(n)
        ip_addresses.append( eval_ip )

    for ip in ip_addresses:
        _pkt = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip)
        ans, unans = srp( _pkt, iface=_interface, timeout=0.1, verbose=False)
        for snt, recv in ans:
            if recv:
                print("Host Alive: %s - %s" % (recv[ARP].psrc, recv[Ether].src))

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("CTRL+C pressed. Exiting. ")
        sys.exit(0)
~

 

00012 扫描局域网

标签:ESS   col   inpu   app   inter   interrupt   imp   exiting   pre   

原文地址:https://www.cnblogs.com/python-abc/p/11780401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!