in reply to Finding your IP address with Perl

I've not used it myself yet, but CPAN module Sys::HostIP appears to be what you're looking for.   From the module source:
NAME Sys::HostIP - Try really hard to get IP addr. SYNOPSIS use Sys::HostIP; $ipaddr= hostip; # get (text) dotted-decimal ip use IO::Socket; use Sys::Hostname; # Have to try non-cannonical name first, since there # is a better chance the computer knows itself than # of DNS knowing it. if($^O eq 'MSWin32') # check ipconfig.exe # (Which does all the work of checking the registry, # probably more efficiently than I could.) # check nbtstat.exe # (Which does all the work of checking WINS, # more easily than Win32::AdminMisc::GetHostAddress().) # check /etc/hosts entries # check /etc/lmhosts entries # (It will only be here if the file has been modified since th +e # last WINS refresh, which is unlikely, but might as well try. +) elsif($^O=~ /IX|ux/i) # check /etc/hosts entries # last resort: ping (which can be very slow)
Ya just gotta love cpan.
    cheers,
    Don
    striving for Perl Adept
    (it's pronounced "why-bick")

Replies are listed 'Best First'.
Re: Re: Finding your IP address with Perl (Sys::HostIP)
by $ENV{REMOTE_USER} (Novice) on Dec 04, 2000 at 22:48 UTC
    This module is actually doing what I was reluctant to do which was matching the IP address from `ipconfig` or the /etc/hosts file (depending on the OS) if it doesn't find the IP address based on what Sys::Hostname finds (which is incorrect).

    Oh well, it works.
      I'm glad it works, also curious - why the reluctance?

      BTW, your script sounds like a good candidate for Snippets.   Dunno 'bout other monks, but I'd benefit from seeing it.
          cheers,
          Don
          striving for Perl Adept
          (it's pronounced "why-bick")

        The reluctance is because I don't like relying on regex matches against running other programs. It's often hard to predict errors, or inconsistencies. Besides that, it just seems "kludgy" and I thought there might be a better way to do it.

        The script is actually for updating DHS.org with your dynamic IP address. You can download my first shot at it here. It works fine in cron or MS scheduler. I'll post the relevent portions on the snippets site.
Re: Re: Finding your IP address with Perl (Sys::HostIP)
by $ENV{REMOTE_USER} (Novice) on Dec 04, 2000 at 21:57 UTC
    Thanks! This is exactly what I needed. It seems to work very well on the systems I've tested so far.