Batch File - Finding the IP address

January 25, 2006 at 14:57:32
Specs: win xp pro, p4 3.2 gh
I was looking for an alternative way to find the IP address of a computer that is for sure the internet IP address,

I know about IPCONFIG |FIND "IP" method, but it is not a sure way as it gets last IP address in the list not necessarily the the internet IP address,

and it should connect to internet to find the ip address,
eg. nslookup can show the current ip address but it needs a connection to internet.

Does anybody know an alternative way or a 3rd party program that can do that?

thanx in advance

Shahram.


See More: Batch File - Finding the IP address

Report •


#1
January 25, 2006 at 20:18:42
correction:
it should NOT connect to internet to find the IP address,

I am writing a batch file that finds the ip address and I don't want others (who don't have access to the source)to think it is sending out their information.

Shahram.


Report •

#2
January 26, 2006 at 01:55:51
www.nwtools.com will give you your external IP address

Report •

#3
January 26, 2006 at 17:33:20
that leads to nowhere!!!!!
I am looking for a batch file solution to implnat in my scripts!!!!!
ps.
even if there is a 3rd party executable that finds the internet ip address without connecting to the internet itself, it will do it for me.

any ideas?

?????????


Report •

Related Solutions

#4
January 26, 2006 at 19:30:14
Ok

This is how I used to find the IP address:

IPCONFIG |FIND "IP" > %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
set IP=%IP:~1%
echo %IP% >%temp%\ip.txt
echo The current IP address is "%IP%"

,

I was able to exclude local IP addresses

10.0.0.0 – 10.255.255.255
172.16.0.0 – 172.31.255.255
192.168.0.0 – 192.168.255.255

IPCONFIG |FIND "IP" | find /v " 0.0.0.0" | find /v ": 192.168." | find /v ": 10." | find /v ": 172.16." | find /v ": 172.17." | find /v ": 172.18." | find /v ": 172.19." | find /v ": 172.20." | find /v ": 172.21." | find /v ": 172.22." | find /v ": 172.23." | find /v ": 172.24." | find /v ": 172.25." | find /v ": 172.26." | find /v ": 172.27." | find /v ": 172.28." | find /v ": 172.29." | find /v ": 172.30." | find /v ": 172.31."> %temp%\TEMPIP.txt
FOR /F "tokens=2 delims=:" %%a in (%temp%\TEMPIP.txt) do set IP=%%a
del %temp%\TEMPIP.txt
if "%IP%"=="" (echo You are currently not connected to Internet and you do not have an IP address.) else (set IP=%IP:~1%)
echo %IP% >%temp%\ip.txt
if not "%IP%"=="" echo The new IP Address is "%IP%".


First of all does anybody know an easier way for excluding 172.16.0.0 – 172.31.255.255 rang?

and the 2nd problem is,
169.254.1.0 to 169.254.254.0 is also reserved for DHCP failures and it is not a valid IP address,
Can anybody help me exclude this rang also?


Report •

#5
January 28, 2006 at 07:40:03
Parsing text with a batch file is not an easy task.

Your first post indicates that you're open to alternative methods. If you want I can provide you with a Perl script. Since I'm safe behind a broadband router (i.e. I don't have my computer directly exposed with a public IP), I can't use my ipconfig output do the proper testing. If you post your output of ipconfig, both with and without the public IP, I'll be able to do the proper testing/debugging.


Report •

#6
January 29, 2006 at 14:26:58
If you decide you want to look into using a Perl script, here's the documentation on the module that can extract the info from ipconfig. You may not understand the syntax, but the documentation should give you a good idea of what it can do.

http://search.cpan.org/~jmacfarla/Win32-IPConfig-0.08/lib/Win32/IPConfig.pm


Report •


Ask Question