Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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"; } }


Comment on Answer: How do I get the local internet IP address?
Download Code
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)
    *grin*
    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 !

    UPDATE
    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-12-19 23:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (94 votes), past polls