Home > php教程 > PHP源码 > 判断是否为内网IP

判断是否为内网IP

PHP中文网
Release: 2016-05-22 18:27:08
Original
1539 people have browsed it

判断是否为内网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;
}
Copy after login

                   

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template