[Perl] How to find IP address
gabor at tracert.com
Wed Oct 9 05:37:28 PDT 2002
On Wed, 9 Oct 2002, Oleg Kobets wrote:
> I am trying to write a simple program that finds the current IP address on
> ppp0 interface and mails it to me. I managed to do it with 2 scripts. One
> bash that finds the current IP and other in perl that mails it to me. Now,
> it's a cumbersome way to do a simple task and I am positive that there is a
> function in perl that can return IP of interface, but I was unable to find
> it using perldoc.
> Any help ?
I don't have ppp0 in this machine so I cannot check it but for eth0 here
is the script:
perl -e 'print ((`/sbin/ifconfig eth0`) =~ /inet addr:(\S+)/)'
$ip = ((`/sbin/ifconfig eth0`) =~ /inet addr:(\S+)/);
More information about the Perl