FAQ: How do I find out my IP address

Discussion in 'Perl Misc' started by Sisyphus, Oct 15, 2003.

  1. Sisyphus

    Sisyphus Guest

    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.
    Sisyphus, Oct 15, 2003
    #1
    1. Advertising

  2. Sisyphus

    Eric Wilhelm Guest

    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
    Eric Wilhelm, Oct 15, 2003
    #2
    1. Advertising

  3. Sisyphus

    Sisyphus Guest

    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.
    Sisyphus, Oct 15, 2003
    #3
  4. Sisyphus

    Sisyphus Guest

    Abigail wrote:
    > Sisyphus () wrote on MMMDCXCVII September
    > MCMXCIII in <URL:news:3f8cbd10$0$23587$>:
    > :} 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.
    Sisyphus, Oct 15, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. UJ
    Replies:
    2
    Views:
    725
  2. UJ
    Replies:
    4
    Views:
    709
    John Rivers
    Sep 2, 2005
  3. =?Utf-8?B?QW5kcmV3?=

    Can we find out IP address?

    =?Utf-8?B?QW5kcmV3?=, Mar 17, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    661
    =?Utf-8?B?RWx0b24gVw==?=
    Mar 18, 2006
  4. Daniel Czajko
    Replies:
    3
    Views:
    13,452
    kesahey
    Oct 21, 2009
  5. PerlFAQ Server
    Replies:
    0
    Views:
    116
    PerlFAQ Server
    Feb 23, 2011
Loading...

Share This Page