@echo off & setlocal enableextensions
::
:: Test first
ipconfig|find "IP Address">nul
if %errorlevel% GTR 0 (
echo Not connected
goto :EOF)
::
:: Get the current IP
for /f "tokens=2 delims=:" %%i in (
'ipconfig /all^|find "IP Address"'
) do set ip=%%i
set ip=%ip: =%
echo %ip%
::
:: Look up the IP address on the name server
for /f "tokens=2 delims=:" %%n in (
'nslookup %ip%^|find "Name:"'
) do set name=%%n
set name=%name: =%
echo %name%
endlocal & goto :EOF
The output might be e.g.
D:\TEST>cmdfaq
193.166.122.2
reimari.uwasa.fi
or
D:\TEST>cmdfaq
Not connected
@echo off & setlocal enableextensions
::
:: Test first
ipconfig|find "IP
v4 Address">nul
if %errorlevel% GTR 0 (
echo Not connected
goto :EOF)
::
:: Get the current IP
for /f "tokens=2 delims=:
(" %%i in (
'ipconfig /all^|find "IP
v4 Address"'
) do set ip=%%i
set ip=%ip: =%
echo %ip%
::
:: Look up the IP address on the name server
for /f "tokens=2 delims=:" %%n in (
'nslookup %ip%^|find "Name:"'
) do set name=%%n
set name=%name: =%
echo %name%
endlocal & goto :EOF