|
下面是程序和运行时的结果
#!/usr/bin/perl
print " lease enter you ip address:\n";
chomp($ip_addr=<STDIN>);
@ip_temp=split(/\./, $ip_addr);
print " lease enter you netmask:\n";
chomp($net_mask=<STDIN>);
@net_temp=split(/\./, $net_mask);
for($i=0; $i<4; $i++)
{
$ip_unch[$i]=(($ip_temp[$i]) & ($net_temp[$i]));
printf "%b, %b, %b\n", $ip_temp[$i], $net_temp[$i], $ip_unch[$i];
}
=======================================
C:\Documents and Settings\Alex>perl -w c:\test3.pl
Please enter you ip address:
192.168.0.1
Please enter you netmask:
255.255.255.0
11000000, 11111111, 1010
10101000, 11111111, 101000
0, 11111111, 0
1, 0, 0 |
|