Computing.Net > Forums > Programming > Batch File - Finding the IP address

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File - Finding the IP address

Reply to Message Icon

Name: shahramsh
Date: January 25, 2006 at 14:57:32 Pacific
OS: win xp pro
CPU/Ram: p4 3.2 gh
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: shahramsh
Date: January 25, 2006 at 20:18:42 Pacific
Reply:

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.


0

Response Number 2
Name: jhunt303
Date: January 26, 2006 at 01:55:51 Pacific
Reply:

www.nwtools.com will give you your external IP address


0

Response Number 3
Name: shahramsh
Date: January 26, 2006 at 17:33:20 Pacific
Reply:

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?

?????????


0

Response Number 4
Name: shahramsh
Date: January 26, 2006 at 19:30:14 Pacific
Reply:

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?


0

Response Number 5
Name: FishMonger
Date: January 28, 2006 at 07:40:03 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: FishMonger
Date: January 29, 2006 at 14:26:58 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File - Finding the IP address

Batch - Ping Ip Address scan www.computing.net/answers/programming/batch-ping-ip-address-scan/17335.html

Batch file to remote shutdown network PC's www.computing.net/answers/programming/batch-file-to-remote-shutdown-network-pcs/19105.html

Extract IP address from txt file www.computing.net/answers/programming/extract-ip-address-from-txt-file/13912.html