determining ppp ip address using perl
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 :) |
you are using the regex comparisons incorrectly. the =~ operator will not overwrite the previous data, just replace (with s///g) the text as requested. you should use a different variable, so:
Code:
# do a comparison have a scan through perlop for more info. |
thanks for the pointer,
forgive my dumbness but what is perlop? :study: |
part of the core perl documentation, Perl Operators. i normally get to it by googling for "perldoc perlop" but it will actaully already be on your system using the perldoc command
|
sorry, straight after sending off that reply I googled it..
I should google first, ask dumb questions later :) - ouch me head is hurting after readin the first few paragraphs of it! shouldna had those beers! |
All times are GMT -5. The time now is 06:05 AM. |