Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get IP address 2

Status
Not open for further replies.

carlg

Programmer
Joined
Jun 23, 2004
Messages
88
Location
US
What can I run from the Linux command line that will return my IP address?

I'm not looking for my local IP address.

I have a cable modem that goes into a router, there are then three computers each connected to the router. My local IP address is 192.168.XXX.XX.

I want to retrieve what the outer world sees as my IP address.

Thanks for the help

Carl

 
No,

Just has my local address (192.168.2.96 is the local IP address of the machine)



[user@localhost ~]$ /sbin/ifconfig
eth0 Link encap:Ethernet HWaddr 00:13:D3:E9:05:16
inet addr:192.168.2.96 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::213:d3ff:fee9:516/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:196081 errors:0 dropped:0 overruns:0 frame:0
TX packets:217736 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:25057858 (23.8 MiB) TX bytes:26424642 (25.2 MiB)
Interrupt:17 Base address:0x4000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:3389 errors:0 dropped:0 overruns:0 frame:0
TX packets:3389 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3081016 (2.9 MiB) TX bytes:3081016 (2.9 MiB)

[user@localhost ~]$
 
Go to whatismyip.com. That will show you the IP of your router if you don't have direct access to it.
Mark
 
If you want to see the IP that the "outer world" sees you as, go to and look in the upper right hand corner.

There are a bazillion sites that will show you your IP like that.

Hope this helps.
 
I need to be able to retreive it via a script.

 
Well, looking at your own computer won't help. The IP that the world sees is actually on the ISP side of your router. If your cable modem is like mine, when the router is turned on, it gets it's IP from your ISP with a DHCP request. I don't think you can query this directly.

One way might be to install [tt]lynx[/tt] or [tt]wget[/tt] (if you don't already have them) and make a request to one of the sites mentioned above, then parse out the IP from the response.

Another thing you can do is use a dynamic DNS service. This gives you an Internet domain name, and they keep it pointed to your IP even if it gets changed by your ISP.

Here are a couple...


Just Google "dynamic dns".

Hope this helps.
 
You could also create your own web-page which would do nothing but return your IP address. It would be simpler and more reliable than parsing somebody else's HTML.
 
if you need to use your address in shell scripts it you may use dyndns.org and cut the address out of the html page

Code:
#!/bin/bash

export IP_ADDR=$(curl --silent [URL unfurl="true"]http://checkip.dyndns.org[/URL] | cut -f6 -d " " | cut -d ">" -f2 | cut -d "<" -f1)


echo "$IP_ADDR"


Cheers

QatQat


Life is what happens when you are making other plans.
 
Perfect!!!!!

Thanks !!!!
 
I have a linksys router, which has an HTTP port that you can use to manage the router. It can show information about DHCP leases etc, and unless you update the firmware the format of the page won't change. Might be worth checking if your router has a similar capability.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
QatQat:
Lovely bit of script. Gave you a star. :)



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Not bad - I was thinking traceroute -n and grabbing the second hop, that way you're not dependent upon dyndns.
 
m4ilm4n:
I thought of that, too... but that one line of script was quite cute. :)



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top