我需要每 10 分钟检查一次我的 IP 地址并将其写入 csv 文件(如果它已更改)。但是,我有几个网卡在使用中。如何使用其 MAC 地址在 CMD 中获取特定卡的 IP 地址?
请参阅下文以修改@mousio对另一个问题的回复 。但它对我不起作用!
@echo off
setlocal enabledelayedexpansion
set "MAC1=Physical Address"
set "MAC2=11-11-11-11-11-11"
set MACfound=false
for /f "usebackq tokens=1-2 delims=:" %%f in (`ipconfig /all`) do (
set "item1=%%f"
set "item2=%%g"
if /i "!item1!"=="!MAC1!" if "!item2!"=="!MAC2!" (
set MACfound=true
) else if not "!item1!"=="!item:IPv4 Address=!" if "!MACfound!"=="true" (
echo Your IP Address is: %%g
set MACfound=false
)
)
有关 ipconfig /all 的部分响应,请参见下文
Ethernet adapter Ethernet 3:
Connection-specific DNS Suffix . : xyz.xyz.com
Description . . . . . . . . . . . : Intel(R) 82579LM Gigabit Network Connection
Physical Address. . . . . . . . . : 11-11-11-11-11-11
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : 1111::1111:1111:1111:111111(Preferred)
IPv4 Address. . . . . . . . . . . : 111.11.11.11(Preferred)
Subnet Mask . . . . . . . . . . . : 111.111.1.1
Lease Obtained. . . . . . . . . . : Thursday, July 25, 2019 9:51:30 AM
Lease Expires . . . . . . . . . . : Monday, August 26, 2019 12:33:23 PM
Default Gateway . . . . . . . . . : 111.11.1.1
DHCP Server . . . . . . . . . . . : 111.11.11.11
DHCPv6 IAID . . . . . . . . . . . : 111111111
DHCPv6 Client DUID. . . . . . . . : 11-11-11-11-11-11-11-11-11-11-11-11-11-11
DNS Servers . . . . . . . . . . . : 111.11.11.11
111.11.11.11
NetBIOS over Tcpip. . . . . . . . : Enabled