I need to check my ip address every 10 minutes and write it to a csv file, if it has changed. However, I have several network cards in use. How can I get IP address of a specific card in CMD using its MAC address?
See below for modification of response to another question by @mousio . It didn't work for me though!
@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
)
)
See below for part of response for 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