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

Jonathan picture Jonathan · Sep 27, 2011 · Viewed 9k times · Source

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%

Answer

Arun picture Arun · Sep 29, 2011
for /f "skip=1 tokens=2 delims=: " %f in ('nslookup %COMPUTERNAME% ^| find /i "Address"') do echo %f