use Socket; $net = "192.168.0.0"; $mask = "28"; # /28 is 255.255.255.240 $ip = "192.168.0.5"; print "$ip belongs to $net/$mask\n" if ((net2long($ip) & ~((1 << (32 - + $mask)) - 1 )) == net2long($net)); sub net2long { return unpack("N", inet_aton(shift)); }
2005-01-20 Janitored by Arunbear - added code tags, as per Monastery guidelines
In reply to Re^3: bitwise operators
by fd15k
in thread bitwise operators
by gtdunlap
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |