Perl: the Markov chain saw | |
PerlMonks |
Re: Getting net addy on localhost?by rob_au (Abbot) |
on Nov 27, 2001 at 09:40 UTC ( [id://127731]=note: print w/replies, xml ) | Need Help?? |
The reason that this code is returning 127.0.0.1 is that you are requesting the resolution of the name localhost, which should always be your loopback adapter address - If you want it to resolve your external IP address, you should pass the external hostname you have been assigned. If this is dynamic in nature then you may want to look at other solutions such as Net::Pcap which allow network interfaces to be iterated. Update #1 - I did a bit of digging on a hunch and if you have a known external address that you can connect to, you could make a socket connection to it and then call perlfunc:getsockname on the socket handle (or sockname if you use IO::Socket) to return the packed address of this end of the socket. eg.
Update #2 - And the prize goes to converter for the link to IO::Interface in this post
Ooohhh, Rob no beer function well without!
In Section
Seekers of Perl Wisdom
|
|