FAQ: How do I find out my IP address

S

Sisyphus

Hi,

As per the faq (in faq 9), I tried running the sample program, and I
took a look in etc/resolv.conf, but could not come up with an ip address
that matches the address that currently identifies this machine on the
internet. Running 'hostname' simply returns 'mail.iinet.net.au' (which
is, naturally, what the faq sample program finds and resolves - but I
aint mail.iinet.net.au :)

Any advice on how to do it ?

Cheers,
Rob
 
E

Eric Wilhelm

Hi,

As per the faq (in faq 9), I tried running the sample program, and I
took a look in etc/resolv.conf, but could not come up with an ip address
that matches the address that currently identifies this machine on the
internet. Running 'hostname' simply returns 'mail.iinet.net.au' (which
is, naturally, what the faq sample program finds and resolves - but I
aint mail.iinet.net.au :)

Any advice on how to do it ?

If you are on a dial-up, your best bet is to check the ppp logs or catch
/sbin/ifconfig (which will work even if you aren't on a dial-up) (you can
do it as a user if you are not trying to set anything.)

/sbin/ifconfig ppp0 |perl -e 'while (<>) { /addr:(.*?)\s/ && print $1};'

I'm sure that there is something in /proc, but you'd have to dig to find
it there.

--Eric
 
S

Sisyphus

Eric said:
If you are on a dial-up, your best bet is to check the ppp logs or catch
/sbin/ifconfig (which will work even if you aren't on a dial-up) (you can
do it as a user if you are not trying to set anything.)

/sbin/ifconfig ppp0 |perl -e 'while (<>) { /addr:(.*?)\s/ && print $1};'

The one liner works beautifully :)

Incidentally, the script in the faq works perfectly on my Win32 box
(same ISP). I don't know why 'hostname' on the linux box returns my
ISP's mail server. Maybe something I did during installation of the OS
..... or subsequent configuration ?

Tft, Eric.

Cheers,
Rob
 
S

Sisyphus

Abigail said:
Sisyphus ([email protected]) wrote on MMMDCXCVII September
MCMXCIII in <URL::} Hi,
:}
:} As per the faq (in faq 9), I tried running the sample program, and I
:} took a look in etc/resolv.conf, but could not come up with an ip address
:} that matches the address that currently identifies this machine on the
:} internet. Running 'hostname' simply returns 'mail.iinet.net.au' (which
:} is, naturally, what the faq sample program finds and resolves - but I
:} aint mail.iinet.net.au :)


'hostname' has *NOTHING* to do with IP addresses or names.

The name returned by 'hostname' is just the name of the machine.
Nothing more, nothing less. Machines do *not* have IP addresses.
Interfaces do. A machine can have several interfaces, and an interface
can have several (or no) IP addresses.

Now, 'hostname' often returns a name that's resolvable by DNS, but that's
not necessary.

As for your question, "how to come up with an address that currently
identifies this machine on the internet", that question might be
unanswerable. Your interfaces might have certain IP addresses (which
you can extract for instance with 'ifconfig'), but those might not be
the addresses the machine is identified on the internet. Routers might
do address translation. You should contact your network administrator,
(s)he should know.


Abigail

Thanks for taking the time to elaborate. (I don't actually know how many
interfaces this PC has, btw - I expect only one.)

I was after the address that you would use if you wanted to ping this PC
- and Eric's one liner seems to provide that.

In my code, I'm using:
$name = gethostbyaddr(inet_aton($addr), AF_INET);

where $addr is the numeric form of my current IP address.

One further small puzzle. If I establish a new connection on the linux
box, then $addr changes, and so too does $name.

But on the Win32 box, although $addr changes, $name remains the same.

I'm finding it hard to make sense of that. (Do I need to check my facts ?)

That suggests to me that if I'm online on the Win32 box, someone could
always (eg) ping me simply by knowing what that unchanging $name is.
But as regards the linux box, that is impossible because the $name
always changes. Yet it's the same ISP, and the same mode of connection
(dial up). Doesn't add up - what am I missing ?

Hmmm ... getting a little OT ... please feel free to ignore.

Cheers,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top