Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by arhuman (Vicar)
on Jan 23, 2001 at 14:04 UTC ( [id://53675]=note: print w/replies, xml ) Need Help??


in reply to How do I get the local internet IP address?

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)
    *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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://53675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found