Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re:**3 (rob_au) Getting net addy on localhost?

by belg4mit (Prior)
on Nov 27, 2001 at 10:05 UTC ( #127736=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Getting net addy on localhost?
in thread Getting net addy on localhost?

And let's not get into the fact that you might have multiple IP addresses.

You never said what platform you are on either. If UN*Xy the easiest pure-perl is to parse /etc/sysconfig/network-scripts/ifcfg-*. You might steal the code from http://www.webmin.com/webmin/

--
perl -p -e "s/(?:\w);([st])/'\$1/mg"

  • Comment on Re:**3 (rob_au) Getting net addy on localhost?

Replies are listed 'Best First'.
Re: Re:**3 (rob_au) Getting net addy on localhost?
by rob_au (Abbot) on Nov 27, 2001 at 10:17 UTC
    The method that I pointed out in the addendum to my first post in this thread *should* suffice if you are wanting to resolve the default external IP address of the machine - But I do agree, there is a great amount of 'grey area' on this question given the number of available configurations and methods of interface.

    I don't however agree with the concept of parsing /etc/sysconfig/network-scripts/ifcfg-* - For starters, this is very much a Red Hat (and variant) locale for network configurations, *not* a general *NIX location pragma. Further to this, the idea of relying on text files generated outside of the real scope of the program makes me very nervous - I have rambled on this concept previously and as such won't repeat myself here.

    Suffice to say, if you are going to rely on *any* external source, consider it tainted and evil (-T, -T and -T) until proven otherwise - And even then treat it with care. If I had to rely on an external program source, then I would be looking directly at /sbin/ifconfig (the path of which should be hard-coded into the program, not drawn from an alternate configuration file) and parsing the output of that.

    Just my random thoughts on the matter

     

    Ooohhh, Rob no beer function well without!

      Well I have seen /etc/sysoncfig/network-scripts on other platforms. But I'll take your word on that. However this is one reason why I mentioned webmin which is ultra-cross-platform (even if a little ugly).

      The problem with calling something like ifconfig is relying upon a standard output scheme across platforms... I doubt Sun does it similar to anybody else (afterall they have their own cron, grep, and ping etc.) UPDATE: I do suppose this |P is a bit GNU-centric ;-).

      --
      perl -p -e "s/(?:\w);([st])/'\$1/mg"

        Yep, it seems we are thinking very much alike on this issue - And I do agree, having to rely on the output of *any* external program is less than ideal, but sometimes system permissions and available utilities limit choices.

        The output of /sbin/ifconfig however I think you would find to be much more uniform than the availability of /etc/sysconfig/network-scripts/ifcfg-* files across *NIX platforms - I know for example that my Debian servers don't use these configuration files and so this locale pragma for network configuration cannot even be seen to be consistent across Linux distributions, let alone *NIX platforms.

        Oh, how I yearn for a consistent WIN32 API ... No, hang on a minute, no I don't ... ;-)

         

        Ooohhh, Rob no beer function well without!

Re: Re:**3 (rob_au) Getting net addy on localhost?
by Dogma (Pilgrim) on Nov 27, 2001 at 10:36 UTC
    That is incorrect, '/etc/sysconfig/network-scripts/ifcfg-*' is a RedHat-ism and isn't even portable between all linux distros. As far as I know there is no standard file between unix and unix-like systems for this information. You can try /etc/hosts but that will only give you resolvable interfaces. Parsing the output of '/sbin/ifconfig' is more likely to be portable. (not that portability is the goal here, but we don't know what system your running on) SNMP (if you have it running) would be another possible means of getting interfaces addresses.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127736]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2021-10-22 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?