S
Suk
I'm trying to get the network number given an IP address and subnet
mask on the command line
Why doesnt this work?
#!/usr/local/bin/perl
#
our ($ip,$netmask,@ip,@net,@nw);
$ip=$ARGV[0];
$netmask=$ARGV[1];
@ip=(split(/\./,$ip));
@net=(split(/\./,$netmask));
$i=0;
foreach (@ip) {
$nw[$i]=$_ & $net[$i];
$i++;
}
print "IP: $ip NETMASK: $netmask NETWORK: @nw\n";
# ./shownet 136.19.96.178 255.255.254.0
IP: 136.19.96.178 NETMASK: 255.255.254.0 NETWORK: 014 01 04 0
Yet 136 & 255 on the command line yields the correct answer
# perl
print 136 & 255
136
What's going on ?
mask on the command line
Why doesnt this work?
#!/usr/local/bin/perl
#
our ($ip,$netmask,@ip,@net,@nw);
$ip=$ARGV[0];
$netmask=$ARGV[1];
@ip=(split(/\./,$ip));
@net=(split(/\./,$netmask));
$i=0;
foreach (@ip) {
$nw[$i]=$_ & $net[$i];
$i++;
}
print "IP: $ip NETMASK: $netmask NETWORK: @nw\n";
# ./shownet 136.19.96.178 255.255.254.0
IP: 136.19.96.178 NETMASK: 255.255.254.0 NETWORK: 014 01 04 0
Yet 136 & 255 on the command line yields the correct answer
# perl
print 136 & 255
136
What's going on ?