Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

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

Q&A > network programming > How do I get the local internet IP address? contributed by Anonymous Monk

Same as above, but you can use this to resolve any address through the DNS setup (/etc/resolv.conf or the /etc/hosts file).

use Socket; my $hostname = "somehost.ext"; my @addr = inet_aton($hostname) or return "Unknown or invalid host."; my($a,$b,$c,$d) = unpack('C4', $addr(0)); #change the $addr() to brackets, this form filters brackets out. my $ip = "$a.$b.$c.$d"; print $ip;

Comment on Answer: How do I get the local internet IP address?
Download Code
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 taking refuge in the Monastery: (4)
As of 2014-08-23 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls