search

Home  >  Q&A  >  body text

android - How to distinguish private network from public network in php?

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

淡淡烟草味淡淡烟草味2822 days ago610

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你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...

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-24 11:32:57

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

    reply
    0
  • 大家讲道理

    大家讲道理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);
    }

    reply
    0
  • Cancelreply