Update main.go
parent
10e584f5e6
commit
6afa3a7eca
22
main.go
22
main.go
|
|
@ -14,20 +14,26 @@ func main() {
|
||||||
//modules.ImportDatabaseToHex()
|
//modules.ImportDatabaseToHex()
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
//测试用ip地址
|
//测试用ip地址
|
||||||
//ip := "103.47.100.182"
|
//ip := "192.168.2.134"
|
||||||
//获取访问浏览器ip
|
//获取访问浏览器ip
|
||||||
ip := strings.Split(r.RemoteAddr, ":")[0]
|
ip := strings.Split(r.RemoteAddr, ":")[0]
|
||||||
//fmt.Println("客户端IP地址:", ip)
|
//fmt.Println("客户端IP地址:", ip)
|
||||||
|
|
||||||
if ip == "" {
|
if ip == "" {
|
||||||
w.Write([]byte("Invalid IP"))
|
w.Write([]byte("Invalid IP"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
IP_info = modules.GetIPInformation(ip)
|
if ip != "" {
|
||||||
log.Println("客户端ip:", ip)
|
IPinfo := modules.GetIPInformation(ip)
|
||||||
|
fmt.Println("IP", IPinfo.IP)
|
||||||
|
fmt.Println("IsPrivate", IPinfo.IsPrivate)
|
||||||
|
fmt.Println("PrivateCIDR", IPinfo.PrivateCIDR)
|
||||||
|
if IPinfo.IsPrivate == true {
|
||||||
|
w.Write([]byte("Invalid IP"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if IPinfo.IsPrivate != true {
|
||||||
//使用mmdb查询ip
|
//使用mmdb查询ip
|
||||||
IpIformation := modules.MmdbQueryIP(ip)
|
IpIformation := modules.MmdbQueryIP(IPinfo.IP)
|
||||||
|
|
||||||
//使用MySql查询ip
|
//使用MySql查询ip
|
||||||
//dsn := modules.Readconfig()
|
//dsn := modules.Readconfig()
|
||||||
//IpIformation := modules.MysqlQuery(ip, dsn)
|
//IpIformation := modules.MysqlQuery(ip, dsn)
|
||||||
|
|
@ -43,6 +49,8 @@ func main() {
|
||||||
// 返回 JSON 数据
|
// 返回 JSON 数据
|
||||||
//log.Println(jsonData)
|
//log.Println(jsonData)
|
||||||
w.Write(jsonData)
|
w.Write(jsonData)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
http.ListenAndServe(":8341", nil)
|
http.ListenAndServe(":8341", nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue