1. package main
    2. import (
    3. "log"
    4. "regexp"
    5. )
    6. // 判断是否为内网IP,如果是内网ip, 则返回 true
    7. func isIntranet(ip string) bool {
    8. match1 := regexp.MustCompile(`^(10|100|192|172|127)\.`).FindString(ip)
    9. return len(match1) != 0
    10. }
    11. func main() {
    12. log.SetFlags(log.Lshortfile)
    13. log.Println("192", isIntranet("192.168.1.1")) //true
    14. log.Println("123", isIntranet("123.12.12.12")) //false
    15. }