Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > FAQ: How do I find out my IP address

Reply
Thread Tools

FAQ: How do I find out my IP address

 
 
Sisyphus
Guest
Posts: n/a
 
      10-15-2003
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
--
To reply by email u have to take out the u in kalinaubears.

 
Reply With Quote
 
 
 
 
Eric Wilhelm
Guest
Posts: n/a
 
      10-15-2003
On Tue, 14 Oct 2003 22:17:46 -0500, Sisyphus wrote:

> 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
 
Reply With Quote
 
 
 
 
Sisyphus
Guest
Posts: n/a
 
      10-15-2003
Eric Wilhelm wrote:

>
> 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


--
To reply by email u have to take out the u in kalinaubears.

 
Reply With Quote
 
Sisyphus
Guest
Posts: n/a
 
      10-15-2003
Abigail wrote:
> Sisyphus ((E-Mail Removed)) wrote on MMMDCXCVII September
> MCMXCIII in <URL:news:3f8cbd10$0$23587$(E-Mail Removed) .net.au>:
> :} 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

--
To reply by email u have to take out the u in kalinaubears.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Find out the MAC address of a machine. UJ ASP .Net 4 09-02-2005 10:46 PM
Find out the TCP/IP address someone is one. UJ ASP .Net 2 08-24-2005 07:56 PM
Find out an IP from MAC address on CAtalyst 2950. AM Cisco 3 07-01-2005 05:05 AM
How do I find out my 2950 ip address. Mark Cisco 3 12-31-2003 07:58 AM



Advertisments