Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Answer: How do I get the local internet IP address?

( #53675=categorized answer: print w/ replies, xml ) Need Help??

Q&A > network programming > How do I get the local internet IP address? - Answer contributed by arhuman

Non portable, return the ip address of all hosts found in /etc/hosts...

while (@adrs=(gethostent())[4]) { for my $value (@adrs) { print join '.',unpack('C4',$value); print "\n"; } }

Replies are listed 'Best First'.
Re: Answer: How do I get the local internet IP address?
by arhuman (Vicar) on Jan 23, 2001 at 22:44 UTC
    Or the more perlish (read : normal, not perverted brain have difficulties to understand it)
    while (@adrs=(gethostent())[4]) { map { $\="\n";print join '.',unpack'C4',$_} @adrs }

    BTW I'm sure a Perl Guru, could tell me how to make this even smaller !
    Please show me the light !

    Ooops ! I suddenly realized that even if MY /etc/hosts contains only entries about my local machine, it might not always be the case (in fact it should often contains entries about other machines...).
    So thousand apologizes, but all my posts in this thread do not resolve the problem...
    But my code could be use to get the ip adresses of the machines in /etc/hosts...
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2016-07-28 08:16 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (253 votes). Check out past polls.