瀏覽代碼

配置双十一促销

shen 4 年之前
父節點
當前提交
fa866419f8
共有 1 個文件被更改,包括 0 次插入93 次删除
  1. 0 93
      go/gopath/src/fohow.com/apps/helper/ip.go

+ 0 - 93
go/gopath/src/fohow.com/apps/helper/ip.go

@@ -1,93 +0,0 @@
-package helper
-
-import (
-	"github.com/kayon/iploc"
-	ip2 "lianjia/app/helper/ip"
-	"net"
-)
-
-//返回IP位置
-func GetIPCNInfo(ip string) (address string) {
-	IP := net.ParseIP(ip)
-	if IsPublicIP(IP) {
-		if IP.To4() != nil {
-			db, err := iploc.OpenWithoutIndexes("config/ip/qqwry.dat")
-			if err == nil {
-				defer db.Close()
-				address = db.Find(IP.String()).String()
-			}
-		}
-	} else {
-		address = "局域网"
-	}
-
-	return
-}
-
-//返回IP所在国家
-func GetIPCountry(ip string) (country string) {
-	IP := net.ParseIP(ip)
-	if IsPublicIP(IP) {
-		if IP.To4() != nil {
-			country = GetIP4Country(IP.String())
-		}
-		if IP.To16() != nil {
-			country = GetIP6Country(IP.String())
-		}
-	}
-	return
-}
-
-//返回IP4所在国家
-func GetIP4Country(ip string) (country string) {
-	db, err := ip2.OpenDB("config/ip/IP2LOCATION-LITE-DB1.BIN")
-	if err == nil {
-		defer db.Close()
-		results, err := db.Get_country_short(ip)
-		if err == nil {
-			country = results.Country_short
-		}
-	}
-	return
-}
-
-//返回IP6所在国家
-func GetIP6Country(ip string) (country string) {
-	db, err := ip2.OpenDB("config/ip/IP2LOCATION-LITE-DB1.IPV6.BIN")
-	if err == nil {
-		defer db.Close()
-		results, err := db.Get_country_short(ip)
-		if err == nil {
-			country = results.Country_short
-		}
-	}
-	return
-}
-
-func IsCNIp(ip string) bool {
-	IP := net.ParseIP(ip)
-	if IsPublicIP(IP) {
-		if GetIPCountry(IP.String()) != "CN" {
-			return false
-		}
-	}
-	return true
-}
-func IsPublicIP(IP net.IP) bool {
-	if IP.IsLoopback() || IP.IsLinkLocalMulticast() || IP.IsLinkLocalUnicast() {
-		return false
-	}
-	if ip4 := IP.To4(); ip4 != nil {
-		switch true {
-		case ip4[0] == 10:
-			return false
-		case ip4[0] == 172 && ip4[1] >= 16 && ip4[1] <= 31:
-			return false
-		case ip4[0] == 192 && ip4[1] == 168:
-			return false
-		default:
-			return true
-		}
-	}
-	return false
-}