Home  >  Article  >  php教程  >  判断是否为内网IP

判断是否为内网IP

PHP中文网
PHP中文网Original
2016-05-22 18:27:081494browse

判断是否为内网IP

/** 
 * 判断内网IP
 *
 * @param $ip
 *
 * @returns
 */
function isPrivateIp($ip) {
	//分割字符串
	$token  = strtok($ip, '.');
	//组合数组
	while ($token  !== false)
	{
	$strIP[] = $token;
	$token = strtok(".");

	}
	//判断IP地址是否合法
	if(count($strIP)!=4)
	{
		return false;
	}
	//判断是否为A类内网IP
	if($strIP[0] == '10')
	{
		if($strIP[1]>=0 && $strIP[1] =0 && $strIP[2] =0 && $strIP[3] = 16 && $strIP[1] =0 && 
		$strIP[2] =0 && $strIP[3] =0 && $strIP[2] =0 && $strIP[3] <= 255)
				{
					return true;
				}
			}
		}
		return false;
	}
//错误的IP地址
return false;
}

                   

 以上就是判断是否为内网IP的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn