arp-scan 是一個專門用來掃描區域網段中活動的 IP 和 MAC 位址的工具。
安裝 arp-scan:
bash
複製程式碼
brew install arp-scan
使用 arp-scan 掃描:
bash
複製程式碼
sudo arp-scan --localnet
這將掃描當前區域網絡中的所有設備,並顯示它們的 IP 和 MAC 位址。
sudo arp-scan --localnet
Password:
Interface: en0, type: EN10MB, MAC: a8:60:b6:2a:3f:e4, IPv4: 192.168.0.137
Starting arp-scan 1.10.0 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.0.1 c4:e9:0a:42:e5:28 D-Link International
192.168.0.151 64:d2:c4:b5:0c:40 Apple, Inc.
192.168.0.172 b8:27:eb:85:bb:4e Raspberry Pi Foundation
192.168.0.104 cc:b5:d1:56:b8:7a Beijing Xiaomi Mobile Software Co., Ltd
192.168.0.124 68:ab:bc:5e:11:40 Beijing Xiaomi Mobile Software Co., Ltd
192.168.0.152 0e:94:f8:46:3d:40 (Unknown: locally administered)
192.168.0.177 58:40:4e:e8:1f:92 Apple, Inc.
192.168.0.156 7c:49:eb:17:4a:79 XIAOMI Electronics,CO.,LTD
192.168.0.173 88:13:bf:03:4b:70 (Unknown)
192.168.0.132 f4:34:f0:64:0c:b4 Apple, Inc.
192.168.0.184 88:13:bf:07:27:44 (Unknown)
748 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.10.0: 256 hosts scanned in 1.936 seconds (132.23 hosts/sec). 11 responded
nmap 是一個功能強大的網路掃描工具。你可以通過 Homebrew 來安裝它。
安裝 nmap:
bash
複製程式碼
brew install nmap
掃描區域網段內的所有 IP:
假設你的區域網段是 192.168.1.0/24,你可以運行以下指令:
bash
複製程式碼
nmap -sn 192.168.1.0/24
這將顯示該網段中所有活動的設備,主機名稱跟IP。
nmap -sn 192.168.0.0/24
Starting Nmap 7.95 ( https://nmap.org ) at 2024-09-07 19:03 CST
Nmap scan report for dlinkrouter (192.168.0.1)
Host is up (0.00055s latency).
Nmap scan report for yeelink-light-lamp4_mibtB87A (192.168.0.104)
Host is up (0.017s latency).
Nmap scan report for 192.168.0.114
Host is up (0.023s latency).
Nmap scan report for qmi-plug-2a1c1_mibt1140 (192.168.0.124)
Host is up (0.019s latency).
Nmap scan report for woshiF4F0640CB4 (192.168.0.132)
Host is up (0.0044s latency).
Nmap scan report for qmi-plug-2a1c1_mibtF62D (192.168.0.136)
Host is up (0.063s latency).
Nmap scan report for adam-de-iMac (192.168.0.137)
Host is up (0.000066s latency).
Nmap scan report for 192.168.0.145
Host is up (0.11s latency).
Nmap scan report for keting (192.168.0.151)
Host is up (0.00075s latency).
Nmap scan report for zhimi-airpurifier-mb1_miio87271782 (192.168.0.156)
Host is up (0.0032s latency).
Nmap scan report for 192.168.0.162
Host is up (0.049s latency).
Nmap scan report for raspberrypi (192.168.0.172)
Host is up (0.0011s latency).
Nmap scan report for mpy-esp32 (192.168.0.173)
Host is up (0.076s latency).
Nmap scan report for 192.168.0.177
Host is up (0.00011s latency).
Nmap scan report for Custom-2-ESP32 (192.168.0.184)
Host is up (0.11s latency).
Nmap done: 256 IP addresses (15 hosts up) scanned in 30.16 seconds
方法
3. 使用 ping 掃描(基本方法)
這種方法比較簡單,但不如上面兩個工具強大。你可以使用 ping 循環遍歷整個網段。
範例腳本:
bash
複製程式碼
for ip in $(seq 1 254); do ping -c 1 192.168.1.$ip | grep "64 bytes" & done
這將嘗試 ping 192.168.1.1 到 192.168.1.254 的所有 IP,並顯示有回應的 IP。
nmap 和 arp-scan 是更專業和強大的工具,能夠提供更完整的網路掃描資訊。
ping 適合小規模的簡單掃描,但對於大型網段可能效率不高。