Hi!
I found this script on the net which is supposed to return my ppp ip if up, however it just prints almost the whole of ifconfig... where is it going wrong?
#!/usr/bin/perl
$ip = `/sbin/ifconfig`;
$ip =~ s/(ppp0)(.*)/$2/s;
if (!$1) { print "No connection\n"; }
else {$ip =~ s/inet addr
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/$1/s;
print "IP is $ip\n";
}
the output is:
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1014 errors:0 dropped:0 overruns:0 frame:0
TX packets:1014 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:425188 (415.2 Kb) TX bytes:425188 (415.2 Kb)
Link encap:Point-to-Point Protocol
inet addr:203.221.120.251 P-t-P:203.220.247.178 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:3963 errors:0 dropped:0 overruns:0 frame:0
TX packets:4300 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:2001631 (1.9 Mb) TX bytes:451840 (441.2 Kb)
I am pretty much a perl newbie so any info will help