public ip from command line

  • Thread starter Thread starter Todd and Margo Chester
  • Start date Start date
T

Todd and Margo Chester

Hi All,

Does anyone know how to get your public ip
address from the command line when you are hidden
behind NAT?

-Todd

p.s. please! no GUI answers! I know how to do this
from Firefox, IE, etc.
 
You need to login to the router or switch to get your external IP. The
command line will only reveal information specific to your machine and the
gateway it is using.

--
Best of Luck,

Rick Rogers, aka "Nutcase" - Microsoft MVP

Windows help - www.rickrogers.org
 
Todd said:
Does anyone know how to get your public ip
address from the command line when you are hidden
behind NAT?

-Todd

p.s. please! no GUI answers! I know how to do this
from Firefox, IE, etc.

Well.. The first line of a tracert would show you..

For example:

Start button --> RUN

cmd /k tracert www.google.com

OK.

It would give you something like:

---------
Tracing route to www.l.google.com [64.233.167.104]
over a maximum of 30 hops:

1 1 ms 1 ms 1 ms ip##-###-###-###.blah.bleh.blargh.net
[##.##.###.###]
----------

So the IP address of the first hop would normally be your network's external
IP address.

You might look into this DLL/VBS solution.
http://www.ostrosoft.com/OIT/external_ip.asp

Otherwise....
 
Todd and Margo Chester said:
Hi All,

Does anyone know how to get your public ip
address from the command line when you are hidden
behind NAT?

-Todd

p.s. please! no GUI answers! I know how to do this
from Firefox, IE, etc.

Try this batch file:

Line1 @echo off
Line2 if exist index.html del index.html
Line3 c:\Tools\wget www.whatismyip.com -onul
Line4 for /F "tokens=4 delims=< " %%a in ('type index.html ^| find /i "your
ip is"')
do echo External IP=%%a
Line5 if exist index.html del index.html

You can get wget.exe from http://users.ugent.be/~bpuype/wget/#download.
 
Pegasus said:
Try this batch file:

Line1 @echo off
Line2 if exist index.html del index.html
Line3 c:\Tools\wget www.whatismyip.com -onul
Line4 for /F "tokens=4 delims=< " %%a in ('type index.html ^| find /i "your
ip is"')
do echo External IP=%%a
Line5 if exist index.html del index.html

You can get wget.exe from http://users.ugent.be/~bpuype/wget/#download.

Dude! This is some seriously "cleaver" programming! Wow! How in
the world did you think of it ... I am not even going to ask.

It works perfectly. Thank you.

-Todd
 
Todd said:
Dude! This is some seriously "cleaver" programming! Wow! How in
the world did you think of it ... I am not even going to ask.

It works perfectly. Thank you.

-Todd

Hi Pegisus,

This is my final version of your code. Be careful of
any word wrapping on the wget line (see comments)

-Todd

@echo off
rem Get External (Public) IP address

rem Note: requires wget.exe, which can be downloaded
rem from http://users.ugent.be/~bpuype/wget/#download
rem code taken from a news reply by Pegasus (MVP)

:Start
set wget=.\wget.exe
if exist %wget% goto GetIP
set wget=C:\NtUtil\wget.exe
if exist %wget% goto GetIP
set wget=C:\Tools\wget.exe
if exist %wget% goto GetIP
echo Critical error (Bummer):
echo.
echo Unable to locate wget.exe in .\, C:\NtUtil, C:\Tools
echo wget can be downloaded from
http://users.ugent.be/~bpuype/wget/#download
echo.
goto End


:GetIP
if exist index.html del index.html
rem the follow is one single line. Remove any word wraps
%wget% www.whatismyip.com -onul
for /F "tokens=4 delims=< " %%a in ('type index.html ^| find /i "your
ip is"') do echo External IP=%%a
rem end single line
if exist index.html del index.html
 
Todd and Margo Chester wrote:
Hi Pegisus,

This is my final version of your code. Be careful of
any word wrapping on the wget line (see comments)

-Todd

@echo off
rem Get External (Public) IP address

rem Note: requires wget.exe, which can be downloaded
rem from http://users.ugent.be/~bpuype/wget/#download
rem code taken from a news reply by Pegasus (MVP)

:Start
set wget=.\wget.exe
if exist %wget% goto GetIP
set wget=C:\NtUtil\wget.exe
if exist %wget% goto GetIP
set wget=C:\Tools\wget.exe
if exist %wget% goto GetIP
echo Critical error (Bummer):
echo.
echo Unable to locate wget.exe in .\, C:\NtUtil, C:\Tools
echo wget can be downloaded from
http://users.ugent.be/~bpuype/wget/#download
echo.
goto End


:GetIP
if exist index.html del index.html
rem the follow is one single line. Remove any word wraps
%wget% www.whatismyip.com -onul
for /F "tokens=4 delims=< " %%a in ('type index.html ^| find /i "your
ip is"') do echo External IP=%%a
rem end single line
if exist index.html del index.html
echo.

:End
pause
 
Todd and Margo Chester said:
Dude! This is some seriously "cleaver" programming! Wow! How in
the world did you think of it ... I am not even going to ask.

It works perfectly. Thank you.

-Todd

Thanks for the feedback. This is a standard batch file
task: How to extract a given string out of a text file whose
format is known.
 
Back
Top