[Perl] How to find IP address

Oleg Kobets gwizard at clean-mail.net
Wed Oct 9 03:18:37 PDT 2002


Thanks, that's exactly what I wanted. Simple and elegant.

My bash script is simple:

IP=`/sbin/ifconfig ppp0 | grep inet | awk '{print $2}' | sed 's#addr:##g'`

send $IP

When "send" is a perl program that simply uses Mail::Mailer to send me the
IP.


---
Oleg Kobets
Network Administrator
Breakthrough LTD.
054-747132
03-6349922 Ext 26

"Black hole is God divided by zero"
----- Original Message -----
From: "Offer Kaye" <oferk at oren.co.il>
To: <perl at perl.org.il>
Sent: Wednesday, October 09, 2002 12:08 PM
Subject: RE: [Perl] How to find IP address


> > Hi!
> >
> > 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 ?
> >
>
> 1. Have you searched CPAN (http://search.cpan.org)? There is a module
there
> that seems to have a method for what you want to do:
> http://search.cpan.org/author/LDS/IO-Interface-0.97/Interface.pm
> >From the page:
> "
> $addr = $s->if_addr($ifname [,$newaddr])
> if_addr() gets or sets the interface address. Call with the interface name
> to retrieve the address (in dotted decimal format).
> "
>
> 2. How complicated is the Bash script? Can you list it here? If it is not
> too complicated, perhaps someone will be able+willing to "translate" it to
> Perl for you.
>
> > ---
> > Oleg Kobets
> > Network Administrator
> > Breakthrough LTD.
> > 054-747132
> > 03-6349922 Ext 26
> >
> > "Black hole is God divided by zero"
> >
>
> Hope this helps :-)
> Offer Kaye
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/cgi/listinfo/perl
>




More information about the Perl mailing list