perl 判断ip是否在某个子网

 

#!/usr/bin/perl -w

use Net::IP;

 

my $ip= new Net::IP('192.168.0.0');

 

my $cut=16;

 

my $net1=substr($ip->binip(),0,$cut);

 

my $input=$ARGV[0];

 

my $new=new Net::IP($input);

 

my $net2=substr($new->binip(),0,$cut);

 

print "$net1\n$net2\n";

 

if($net1 eq $net2)

{

  print "yes\n";

}

else{

  print "no\n";

}

 

你可能感兴趣的:(perl,ip判断)