![打印网络内的所有 ipaddress](https://linux22.com/image/1528684/%E6%89%93%E5%8D%B0%E7%BD%91%E7%BB%9C%E5%86%85%E7%9A%84%E6%89%80%E6%9C%89%20ipaddress.png)
我正在尝试执行一种方法来获取连接到路由器(包括无线)的每个 IP 地址和 Mac 地址。
我设法使用 nmap 找出我的网络内有哪些 IP:
nmap -sP 192.168.1.* >> IPs.txt
并返回:
Starting Nmap 7.40 ( https://nmap.org ) at 2017-04-27 18:31 ???? ÷?? ???????
Nmap scan report for 192.168.1.1
Host is up (0.0010s latency).
MAC Address: 2C:E4:12:EF:5B:72 (Sagemcom Broadband SAS)
Nmap scan report for 192.168.1.10
Host is up (0.074s latency).
MAC Address: 48:02:2A:06:A4:6F (B-Link Electronic Limited)
Nmap scan report for 192.168.1.11
Host is up (0.0030s latency).
MAC Address: 6E:2E:85:FF:FF:FF (Unknown)
Nmap scan report for 192.168.1.12
Host is up (0.071s latency).
MAC Address: 8C:18:D9:C8:A3:94 (Shenzhen RF Technology)
Nmap scan report for 192.168.1.13
Host is up (0.070s latency).
MAC Address: B4:43:0D:AA:3F:6C (Broadlink)
Nmap scan report for 192.168.1.16
Host is up (0.0020s latency).
MAC Address: F8:D1:11:18:74:89 (Tp-link Technologies)
Nmap scan report for 192.168.1.17
Host is up (0.056s latency).
MAC Address: 34:23:BA:4C:82:42 (Samsung Electro-mechanics(thailand))
Nmap scan report for 192.168.1.20
Host is up.
Nmap done: 256 IP addresses (8 hosts up) scanned in 8.24 seconds
我正在寻找一种方法来过滤内容并且打印是这样的:IP:MAC;
谢谢!
答案1
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
For /f "tokens=1-5" %%A in (
'nmap -sP 192.168.1.*'
) Do If /I "%%B" equ "scan" (
set "IP=%%E"
) Else if /I "%%A" equ "MAC" (
Echo !IP!,%%C;
)
测试数据的示例输出:
192.168.1.1,2C:E4:12:EF:5B:72;
192.168.1.10,48:02:2A:06:A4:6F;
192.168.1.11,6E:2E:85:FF:FF:FF;
192.168.1.12,8C:18:D9:C8:A3:94;
192.168.1.13,B4:43:0D:AA:3F:6C;
192.168.1.16,F8:D1:11:18:74:89;
192.168.1.17,34:23:BA:4C:82:42;