Link to home
Start Free TrialLog in
Avatar of kapitany
kapitany

asked on

internet ip address with adsl

Hi,

Is there a way to get my current ip address with a command in linux?
I can use ip lookup web pages, but it's not 100% working. So I would like to find something within my box...
I also could use the command ifconfig but it gives me the static IP address assigned to this machine in the internal network and not the internet IP address.
Any trick?

BR,
kapi
Avatar of vsamtani
vsamtani

The shell script will give you the IP address and netmask of a specified network interface. I am assuming your external address is on interface ppp0.

----------------------


#!/bin/sh

external_interface="ppp0"

ext_ip="`/sbin/ifconfig $external_interface | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
ext_netmask="`/sbin/ifconfig $external_interface | grep 'inet addr' | awk '{print $4}' | sed -e 's/.*://'`"

echo $ext_ip
echo $ext_netmask

Avatar of kapitany

ASKER

Hi,
The script works fine but the IP address is still an internal IP address. Maybe I was not giving enough details.
So I have an ADSL modem connected to the ISP's services. I have a static IP within the ISP's network. When I connect to the outside world (internet) my internal static IP is mapped to an external, so I got an external IP.
I think the only way to get this external IP to connect somewhere and asking the other what IP address he sees.. But I thought that there might be some linux commad to do this.. The ifconfig script works fine but as I told it still gives the static IP that was assign to me only for the internal trafic...
Thx,
kapi
ASKER CERTIFIED SOLUTION
Avatar of vsamtani
vsamtani

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think that the only way you'll get the "outside IP" of your ADSL box is to connect to some Internet host that can look at the source IP of your connection or possibly by getting into the ADSL box and asking it what the "outside IP" is. What ADSL box do you have?
kapitany, listen there is a command that will give you ALL the connections that your box has "netstat" do a man on the netstat command "$ man netstat", so you can see what  ip's your are connected to. expect a large volume of output, i recomend you pipe it to "more" ex: "$ netstat -a | more"
there you will see the information I believe you are looking for
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange