Get THIS computers IP address - :getIP

The getIP function filters the IP address from the ipconfig command output and returns it to the caller.

Code

:getIP — return THIS computers IP address

::     — %~1 - out, IP

SETLOCAL

set ip=

for /f “tokens=2,* delims=:. ” %%a in (’”ipconfig|find “IP Address”"‘) do set ip=%%b

( ENDLOCAL & REM RETURN VALUES

IF “%~1″ NEQ “” (SET %~1=%ip%) ELSE (echo.%ip%)

)

goto :eof

Test Code

rem.show this computers IP address

call:getIP ip

echo This computers IP is: %ip%

Test Code Output

This computers IP is: 4.239.36.199

Leave a Reply

You must be logged in to post a comment.