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

New User

Aug 10, 2009, 10:46 PM

Views: 5235
Please help to solve my problem

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.

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

if(/inet addr:([\d.]+)/){
# print "$1\t";
# print "$1\n";
#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: 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 from above result.

thank you



Aug 12, 2009, 12:49 AM

Views: 5217
Re: [kushan] Please help to solve my problem

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:

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.

New User

Aug 14, 2009, 6:25 AM

Views: 5210
Re: [spider] Please help to solve my problem

Thank you very much spider..it works now.