The designated network is a private network, except that all are public networks. How to distinguish it? Anyone who has experience in similar needs can please tell me
世界只因有你2017-05-24 11:32:57
First of all, you need to understand what the special addresses specified in RFC1918 are, and then here is a better answer/q/10...
伊谢尔伦2017-05-24 11:32:57
Is it not possible to determine the IP address?
Why should we distinguish?
大家讲道理2017-05-24 11:32:57
The first thing that can be determined is that the internal network IP starts with 127.,10.,192.168.,172., so it is easy to distinguish the internal and external network IPs.
/*
区分是否是内网ip
@param $ip string IP
@return bool true/false
*/
function isLocal($ip){
return preg_match('%^127\.|10\.|192\.168|172\.(1[6-9]|2|3[01])%',$ip);
}