Upgrade Network Devices        syncLMS-One-MikroTik-PPPoE        getLMS-One-MikroTik-StatsByLMS        syncLMS-Multi-MikroTik-PPPoE       

inne

 

test IPv4 [PHP, Perl]

   09-11-2017 21:20:00       Odwiedziny: 294

Zgodne z RFC 5735.

## Kod: PHP [*.php]

<?php
echo isPublicIP("8.8.8.8");
# lub
echo isPublicIPLong("8.8.8.8");


function isPublicIP($ipAddr) {
 $result = 1;

   if(preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $ipAddr)) {
	$ipLong = ip2long($ipAddr);

	   if($ipLong <= 16777215 or 
		($ipLong >= 2130706432 and $ipLong <= 2147483647) or 
		($ipLong >= 2851995648 and $ipLong <= 2852061183) or 
		($ipLong >= 167772160 and $ipLong <= 184549375) or 
		($ipLong >= 2886729728 and $ipLong <= 2887778303) or 
		($ipLong >= 3232235520 and $ipLong <= 3232301055) or 
		 $ipLong >= 3758096384) {

		$result = 0;
	   }

   } else {
	$result = 0;
   }

 return $result;
}


function isPublicIP($ipAddr) {
 $result = 1;

   if(preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $ipAddr)) {
	$parts=explode(".", $ipAddr);

	   foreach($parts as $ipParts) {
		   if(intval($ipParts)>255 || intval($ipParts)<0) {
			$result = 0;
		   }
	   }

	   if(intval($parts[0])==0 || intval($parts[0])==10 || intval($parts[0])==127 || (intval($parts[0])>223 && intval($parts[0])<240)) {
		$result = 0;
	   }

	   if((intval($parts[0])==192 && intval($parts[1])==168) || (intval($parts[0])==169 && intval($parts[1])==254)) {
		$result = 0;
	   }

	   if(intval($parts[0])==172 && intval($parts[1])>15 && intval($parts[1])<32) {
		$result = 0;
	   }

   } else {
	$result = 0;
   }
 return $result;
}
?>


## Kod: Perl [*.pl]

#!/usr/bin/perl
use Socket;

print isPublicIP("8.8.8.8");
# lub
print isPublicIPLong("8.8.8.8");


sub isPublicIPLong {
 my ($ipAddr) = @_;
 my $result = 1;

   if($ipAddr =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
	my $ipLong = unpack('N', inet_aton($ipAddr));

	   if($ipLong <= 16777215 or 
		($ipLong >= 2130706432 and $ipLong <= 2147483647) or 
		($ipLong >= 2851995648 and $ipLong <= 2852061183) or 
		($ipLong >= 167772160 and $ipLong <= 184549375) or 
		($ipLong >= 2886729728 and $ipLong <= 2887778303) or 
		($ipLong >= 3232235520 and $ipLong <= 3232301055) or 
		 $ipLong >= 3758096384) {

		$result = 0;
	   }

   } else {
	$result = 0;
   }

 return $result;
}


sub isPublicIP {
 my ($ipAddr) = @_;
 my $result = 1;

   if($ipAddr =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
	my @parts = split(/\./, $ipAddr);

	   foreach my $ipParts (@parts) {
		   if(int($ipParts)>255 or int($ipParts)<0) {
			$result = 0;
		   }
	   }

	   if(int($parts[0])==0 or int($parts[0])==10 or int($parts[0])==127 or (int($parts[0])>223 && int($parts[0])<240)) {
		$result = 0;
	   }

	   if((int($parts[0])==192 && int($parts[1])==168) or (int($parts[0])==169 && int($parts[1])==254)) {
		$result = 0;
	   }

	   if(int($parts[0])==172 && int($parts[1])>15 && int($parts[1])<32) {
		$result = 0;
	   }

   } else {
	$result = 0;
   }

 return $result;
}



Copyright seszu © 30.10.2010-2020.