perl 判断ip是否在某个子网
#!/usr/bin/perl -wuse Net::IP;
my $ip= new Net::IP('192.168.0.0');
my $cut=16;
my $net1=substr($ip->binip(),0,$cut);
my $input=$ARGV;
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";
}
页:
[1]