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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


New User

Aug 10, 2009, 10:46 PM

Post #1 of 3 (5321 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.

$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

Post #2 of 3 (5303 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:

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

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

Thank you very much 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