Apagada docs

Aprendiendo a programar el pasado

Herramientas de usuario

Herramientas del sitio


Get My local IP Address using batch files

Imagine you have an app that needs to be configured with your local ip number before you start it, like Construct2. You could obtain ip address from powershell, but in some systems powershell is restricted to administrators.

You could use a python or sed script to get the IP address from command line, but, what if you want to use windows primitives only?

This batch file gets the exit of ipconfig, finds a local IPv4 address and returns it as a variable. (%IPv4%)

@echo off
rem This batch file works in windows command line only.
rem It needs extended commands like 
rem "exit /B", "for /F" y "set /A"
if %1.==""K"". goto :findandexit
if %1.==L. goto :ipfound

rem "FOR" does not allow backquoted commands with pipes  ("|"), so
rem we will call this same file to execute "ipconfig | find IPv4" and
rem gets the text after the first colon ":" on output text.
rem The "\" delimiter is needed to get rid of spurious "C:\blah\blah\>"
rem output generated on batch processing.
for /F  "usebackq tokens=2 delims=:\" %%a in (`%0 ""K""`) do call %0 L %%a
exit /B
goto :xit
rem testing for number...
set IPV4t=%2
set IPV4t=%IPV4T:.=%
set /A IPv4t=%IPV4t%-%IPV4t%
if %ipv4t%==0 set IPV4=%2
set ipv4t=
echo IPV4=%2
exit /B
goto :xit
ipconfig |find "IPv4"
exit /B
goto :xit
Este sitio web utiliza cookies. Al utilizar el sitio web, usted acepta almacenar cookies en su computadora. También reconoce que ha leído y entendido nuestra Política de privacidad. Si no está de acuerdo abandone el sitio web.Más información
en/bat/getmyip.cmd_get_ip_number_using_batch_file.txt · Última modificación: 2017/01/01 05:23 por nepenthes