How to check IPs on same subnet?
In many cases, you might want to check whether an ip address falls under a same subnet or not. It can be done both in perl and php using the Network library.
For PHP use Net IP4 library
For PERL use Net::IP library
<?php
// check for IP falls in same subnet or not
include("Net/IPv4.php");
$objIP = new Net_IPv4();
echo $objIP->ipInNetwork("192.xx.xx.xx", "192.xx.xx.x/24") ? "Same Subnet" : "Outside the Subnet";
?>
In perl you can use Net::IP module
#!/usr/bin/perl
use NetAddr::IP;
my $netwrk = NetAddr::IP->new('192.xx.xx.x/24');
my $ip = '192.x.x.x';
if ($ip->within($netwrk)) {
print "IP is in same subnet";
} else {
print "IP outside the subnet";
}
Similar Posts:
- DNS-Test :: Free dns checking tool script!
- Perl Net DNS Tutorial for Querying DNS Servers
- Perl modules CPAN error memory allocation
- Install Apache Mod_Substitute
- BSNL Dataone – Automatically connect to Internet when modem switched ON
- No More Secrecy for Swiss Bank Accounts!
- Enabling ModRewrite in XAMPP Apache
- How to unzip ZIP files with PHP
- How to Install suPHP in Linux
- Cannot find either the gdbm or the db library with Courier-IMAP

