ritzsec/Network_Scanner_Tool

GitHub: ritzsec/Network_Scanner_Tool

这是一个基于Scapy的Python工具,用于通过ARP请求扫描本地网络中的活跃设备,解决网络设备发现和映射的问题。

Stars: 0 | Forks: 0

# 网络扫描工具 ## 🎯 目标 网络扫描项目旨在扫描给定的IP范围,通过ARP协议识别网络中的活跃设备。该工具利用Scapy库向指定范围内的所有IP地址发送ARP请求,并收集响应以获取活跃设备的关联IP地址和MAC地址。 ### 🧠 学到的技能 - 理解本地网络通信中使用的ARP(地址解析协议)。 - 使用Scapy库进行网络数据包构建和分析的实践经验。 - 熟悉网络扫描和发现技术。 - 能够通过分析MAC地址和IP地址来识别网络中的设备。 ### 🛠 使用的工具 - **Scapy**:一个强大的基于Python的交互式数据包处理程序。 - **以太网帧**:用于在网络上发送数据以识别活跃设备。 - **ARP请求**:一种用于在本地网络中发现设备的协议。 ## 🛠 逐步代码分解 ### **步骤 1**:导入必要的库 导入Scapy的库:ARP用于构建**ARP**请求,**Ether**用于创建以太网帧,**srp**用于发送数据包并接收响应。 ``` from scapy.all import ARP, Ether, srp ``` ### **步骤 2**:定义网络扫描函数 - 定义一个scan_network()函数,该函数接收IP范围作为输入。 - 使用广播地址(ff:ff:ff:ff:ff:ff)创建一个ARP请求和一个以太网帧。 ``` def scan_network(ip_range): # Create ARP request packet arp = ARP(pdst=ip_range) ether = Ether(dst="ff:ff:ff:ff:ff:ff") packet = ether / arp print(f"Scanning {ip_range}... Please wait.") ``` ### **步骤 3**:发送数据包并捕获响应 使用**srp()**发送构建的ARP请求,并在2秒超时内收集响应。 ``` # Send the packet and receive responses result = srp(packet, timeout=2, verbose=False)[0] ``` ### **步骤 4**:处理并显示结果 - 遍历接收到的响应,提取IP和MAC地址。 - 打印网络中可用设备的列表。 ``` # Print out the results devices = [] for sent, received in result: devices.append({'ip': received.psrc, 'mac': received.hwsrc}) print("\nAvailable Devices in the Network:") print("IP" + " "*18+"MAC") print("-"*40) for device in devices: print("{:16} {}".format(device['ip'], device['mac'])) ``` ### **步骤 5**:主代码执行 要求用户输入一个IP范围(例如,**192.168.__.__/24**),然后调用**scan_network()**函数开始扫描。 ``` if __name__ == "__main__": target_ip = input("Enter the IP range (e.g., 192.168.1.0/24): ") scan_network(target_ip) ``` ## 🛠 文件结构 ``` │ ├── network_scanner.py # Your Python script ``` ## 📖 整体说明 ``` The Network Scanner tool is designed to discover active devices in a local network by utilizing ARP (Address Resolution Protocol) requests. This tool helps users map out devices connected to their network by sending ARP requests to all IP addresses within a specified range. It then collects responses that include the IP and MAC addresses of active devices. This is achieved by sending out Ethernet frames with ARP requests, and the tool listens for any responses from devices that are reachable within the given IP range. The results are then displayed in a clean format showing the IP and MAC addresses of all the available devices on the network. The tool uses the Scapy library, a powerful Python library used for network packet crafting and analysis, to automate the process of scanning the network. By utilizing ARP requests, it helps identify devices in the network even without knowing the specific IP addresses of the devices, which is useful for network auditing and discovery tasks. ``` ## ⚠️ 免责声明 此工具仅用于教育和授权测试目的。 未经明确许可,请勿使用它扫描网络或设备。 未经授权扫描网络可能是非法和不道德的。 ## 👤 作者 充满好奇心和咖啡因的产物 ☕ **ritzsec** [GitHub 个人资料](https://github.com/your-username)
标签:ARP协议, IP扫描, MAC地址识别, Python编程, Scapy库, 二进制发布, 云存储安全, 后渗透, 开源工具, 本地网络, 网络安全, 网络工具, 网络扫描, 设备发现, 设备管理, 逆向工具, 隐私保护