Thursday, August 9, 2012

Obtaining your IP address

There are many different methods to get your IP address in batch, but this is my new favorite.

 for /f "" %%A in ('hostname') do set HOSTNAME=%%A  
 for /f "tokens=2 delims=[]" %%A in ('ping %HOSTNAME% -4 -n 1 ^| find "Pinging"') do (  
     set IPADDR=%%A  
 )  

You can also change whether you want an IPv4 address or IPv6 address by changing the -4 argument to -6.

No comments:

Post a Comment