Batch file to get TCP/IP info from local LAN
Posted by Jeroen Pluimers on 2011/08/24
I needed an automated way of inspecting the local LAN.
- find the TCP/IP gateways/netmasks
- enumerate all the IP addresses on each subnet (assuming the netmask is 255.255.255.0)
- ping each IP address and get ARP info, and dump that to the console
There are other tools that can do this too (like Angry IP Scanner), and more but the ones I tried could not copy the output to the clipboard.
find local subnets:
@echo off setlocal for /F "tokens=2,12,14 delims=: " %%i in ('ipconfig') do ( :: echo %%i if !%%i!==!Mask! call :mask %%k if !%%i!==!Gateway! call :gateway %%j ) endlocal goto :exit :mask if !%*! == !! goto :exit set netmask=%* goto :exit :gateway if !%*! == !! goto :exit echo netmask=%netmask% gateway=%* goto :exit :exit
@echo off :: http://www.robvanderwoude.com/ntfortokens.php for /F "tokens=1,2,3,4,5,6,7,8,9,10,* delims==. " %%a in ('find-local-subnets.bat') do ( :: simplify: only take the first three bytes from the netmask call :subnet %%g.%%h.%%i ) goto :exit :subnet for /l %%n in (1,1,254) do call :ip %1 %%n goto :exit :ip echo %1.%2 for /F "tokens=1,2,3,* delims= " %%m in ('arpping.bat %1 %2 ^| find "dynamic"') do ( echo %%m %%n %%o ) goto :exit :exit
:: http://www.windowsitpro.com/article/monitoring-and-analysis/how-can-i-get-a-list-of-mac-to-ip-addresses-on-the-network- REM arpping.bat ping -n 1 -l 1 %1.%2 arp -a %1.%2