Search code examples
command-linebatch-fileipcommand-promptipconfig

How do I do set a variable in Windows command line to an IP?


Is there an easy way to grab the IP address from my service provider and put it into a variable via command prompt? Something like the following:

SET hostIP = nslookup \address
ECHO %hostIP%

Or

SET hostIP = ipconfig \address
ECHO %hostIP%

Solution

  • for /f "skip=1 tokens=2 delims=: " %f in ('nslookup %COMPUTERNAME% ^| find /i "Address"') do echo %f