@echo off setlocal enabledelayedexpansion :: Read the MAC, IP address, and gateway pairs from the file for /f "tokens=1,2,3 delims=," %%a in (C:\temp\MAC_IP_Gateway.txt) do ( set "desiredMAC=%%a" set "desiredIP=%%b" set "desiredGateway=%%c" echo DesiredMAC: !desiredMAC! echo DesiredIP: !desiredIP! echo DesiredGateway: !desiredGateway! :: Get all network adapters for /f "tokens=1,2,3 delims=," %%x in ('getmac /v /fo csv /nh') do ( set "connection=%%x" set "adapter=%%y" set "mac=%%z" set "connection=!connection:~1,-1!" set "adapter=!adapter:~1,-1!" set "mac=!mac:~1,-1!" echo Connection: !connection! echo Adapter: !adapter! echo MAC Address: !mac! :: Check if the MAC address matches the desired one if "!mac!"=="!desiredMAC!" ( echo Found the NIC echo Connection: !connection! echo Adapter: !adapter! echo MAC Address: !mac! :: Set the IP address and gateway :: Replace "255.255.255.0" with the desired subnet mask set "command=netsh interface ip set address "!connection!" static !desiredIP! 255.255.255.0 !desiredGateway! 1" echo Windows Command: !command! @echo on !command! @echo off ) else ( echo Not found the desired MAC ) ) )