扫描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来处理,这个比方法一会快一点。

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

相关推荐
e***75397 小时前
在 Windows 上生成本地 SSL 证书并使用 HTTPS 访问本地 Nginx 服务器
windows·https·ssl
laocooon5238578868 小时前
实现了一个新闻数据采集与分析系统python
linux·服务器·windows
_oP_i17 小时前
Win11 性能调优实用指南
windows
保持低旋律节奏18 小时前
C++——C++11特性
开发语言·c++·windows
ol木子李lo18 小时前
Visual studio 2022高亮汇编(ASM)语法方法
汇编·ide·windows·visual studio
王柏龙20 小时前
Win11 无法找到本地组策略编辑器的解决方法
windows·策略模式
q***098020 小时前
Windows 11 如何配置node.js
windows·node.js
q***471821 小时前
Windows 上彻底卸载 Node.js
windows·node.js
柳暗花再明1 天前
Visio 中设置文本框背景透明的方法
人工智能·windows
天庭鸡腿哥1 天前
大小只有4K的软件,可让系统瞬间丝滑!
运维·服务器·windows·microsoft·everything