扫描IP段内的使用的IP

扫描IP段内的使用的IP

方法一:命令行

命令行进入

bash 复制代码
for /L %i IN (1,1,254) DO ping -w 1 -n 1 192.168.3.%i
bash 复制代码
arp -a

方法二:python

python 复制代码
from scapy.all import ARP, Ether, srp
import keyboard


def scan_network(ip_range):
    # 创建一个ARP请求包
    arp = ARP(pdst=ip_range)
    ether = Ether(dst="ff:ff:ff:ff:ff:ff")
    packet = ether / arp

    # 发送包并接收响应
    result = srp(packet, timeout=2, verbose=0)[0]

    # 解析响应
    devices = []
    for sent, received in result:
        devices.append({'ip': received.psrc, 'mac': received.hwsrc})

    return devices


if __name__ == "__main__":
    # 指定要扫描的网段
    target_ip_range = str(input("请输入IP(格式:192.168.20.0/23):"))
    # target_ip_range = "192.168.20.0/23"
    active_devices = scan_network(target_ip_range)
    print("Active devices in the network:")
    for device in active_devices:
        print(f"IP: {device['ip']}, MAC: {device['mac']}")
    print("按空格键退出")
    # 检查是否有按键被按下
    while True:
        if keyboard.is_pressed('space'):
            print("Exiting...")
            break

可以用pyinstaller打包成exe来处理,这个比方法一会快一点。

还有优化空间,因为目前是单线程来的

相关推荐
MyBFuture10 分钟前
C#数组详解:一维二维与交错数组
开发语言·windows·c#·visual studio·vision pro
生活很暖很治愈20 分钟前
GUI自动化测试[3]——控件&数鼠标操作
windows·python·功能测试·测试工具
HAPPY酷38 分钟前
构建即自由:一份为创造者设计的 Windows C++ 自动化构建指南
开发语言·c++·ide·windows·python·策略模式·visual studio
忘忧记1 小时前
某小说数据分析过程
windows·数据挖掘·数据分析
PPPPPaPeR.1 小时前
环 境 变 量
linux·运维·windows
开开心心就好2 小时前
键盘映射工具改键位,绿色版设置后重启生效
网络·windows·tcp/ip·pdf·计算机外设·电脑·excel
Andy Dennis3 小时前
dell g3电脑出现no bootable device的处理方式
windows·电脑
一点事3 小时前
windows:ELK搭建(单机)
windows·elk·jenkins
次旅行的库4 小时前
不能将windows本地虚拟环境打包到实验室服务器
linux·windows·conda
艾莉丝努力练剑4 小时前
【QT】信号与槽
linux·开发语言·c++·人工智能·windows·qt·qt5