android - How to distinguish private network from public network in php?
淡淡烟草味
淡淡烟草味 2017-05-24 11:30:57
0
3
569

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

淡淡烟草味
淡淡烟草味

reply all(3)
世界只因有你

First of all, you need to understand what the special addresses specified in RFC1918 are, and then here is a better answer/q/10...

伊谢尔伦

Is it not possible to determine the IP address?
Why should we distinguish?

大家讲道理

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);
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template