LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-16-2003, 11:18 PM   #1
Smerk
Member
 
Registered: Oct 2002
Location: Cairnsian, Oz
Distribution: Debian testing/unstable, knoppix/debian fudged router!
Posts: 169

Rep: Reputation: 30
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
 
Old 01-17-2003, 03:41 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
$ifconfig=~/(blah)(ip)/;
#use the variable
my $ip = $2;
hth (hopefully)

have a scan through perlop for more info.
 
Old 01-17-2003, 06:49 AM   #3
Smerk
Member
 
Registered: Oct 2002
Location: Cairnsian, Oz
Distribution: Debian testing/unstable, knoppix/debian fudged router!
Posts: 169

Original Poster
Rep: Reputation: 30
thanks for the pointer,
forgive my dumbness but what is perlop?
 
Old 01-17-2003, 07:00 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
 
Old 01-17-2003, 07:12 AM   #5
Smerk
Member
 
Registered: Oct 2002
Location: Cairnsian, Oz
Distribution: Debian testing/unstable, knoppix/debian fudged router!
Posts: 169

Original Poster
Rep: Reputation: 30
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!

Last edited by Smerk; 01-17-2003 at 07:14 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl question: how to insert an e-mail address in a script Pastorino Programming 3 08-08-2005 08:28 AM
Ethernet address for proxy ARP problem with PPP GuestFox Slackware 2 06-05-2005 07:17 AM
Linux: Determining MAC address from C Mad_C Programming 9 02-11-2005 04:27 AM
A laptop, a pc, a serial null cable modem, ppp, and perl tomascebrian Linux - Networking 0 11-25-2003 04:40 AM
sending an email to a email address after a perl operation meluser Programming 9 04-07-2003 01:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration