CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Please help to solve my problem

 



kushan
New User

Aug 10, 2009, 10:46 PM

Post #1 of 3 (2433 views)
Please help to solve my problem Can't Post

Hi Everybody.

i wrote a perl script to get the ip informaion of the interface in my server.

Its working, but i only interest about the network address and its CIDR noration prefix.

this my code for your refernce.

#!/usr/bin/perl
$command="/sbin/ifconfig eth0:0";
@filter=qx|$command |or die("Can't get info from ifconfig: ".$!);

foreach(@filter){
if(/inet addr:([\d.]+)/){
# print "$1\t";
$para1=$1;
}
}
foreach(@filter){
if(/Mask:([\d.]+)/){
# print "$1\n";
$para2=$1;
}
}
#print "$para1\t";
#print "$para\n";

@CIDR=`/sbin/ipcalc-copy $para1 $para2| grep 'Network: '`;
print "@CIDR\n";




this is working fine, its give me the result as ;

Network: 192.168.0.0/28 11000000.10101000.00000000.0000 0000

But i need only the Decemial format, i dont need the binary format, can anybody help me to filter the 192.168.0.0/28 from above result.



thank you

Kushan


spider
User


Aug 12, 2009, 12:49 AM

Post #2 of 3 (2415 views)
Re: [kushan] Please help to solve my problem [In reply to] Can't Post

I have not looked into how you got to that network-string, but I guess you have control on that part.
If you have that string in a scalar you could do something like this:

Code
if($networkstring =~ /(\d+\.\d+\.\d+\.\d+\/\d+)/){ 
$ip_info = $1 ;
}


\d+ meens one or more digits.
Uses a \ to escape the dots in the ip and the / before the mask.


kushan
New User

Aug 14, 2009, 6:25 AM

Post #3 of 3 (2408 views)
Re: [spider] Please help to solve my problem [In reply to] Can't Post

Thank you very much spider..it works now.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives