Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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? 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 perusing the Monastery: (11)
As of 2016-06-25 18:21 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (326 votes). Check out past polls.