1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > golang根据IP地址获取归属地信息-ip2location版

golang根据IP地址获取归属地信息-ip2location版

时间:2019-10-26 13:27:28

相关推荐

golang根据IP地址获取归属地信息-ip2location版

golang根据IP地址获取归属地信息-ip2location版

package testimport ("fmt""/ip2location/ip2location-go")func main() {//(文件:IP2LOCATION-LITE-DB3.IPV6.BIN) 下载地址:/db, err := ip2location.OpenDB("./IP2LOCATION-LITE-DB3.IPV6.BIN")if err != nil {fmt.Print(err)return}ip := "36.100.232.222"results, err := db.Get_all(ip)if err != nil {fmt.Print(err)return}fmt.Printf("ip: %s\n", ip)fmt.Printf("country_short: %s\n", results.Country_short)fmt.Printf("country_long: %s\n", results.Country_long)fmt.Printf("region: %s\n", results.Region)fmt.Printf("city: %s\n", results.City)fmt.Printf("isp: %s\n", results.Isp)fmt.Printf("latitude: %f\n", results.Latitude)fmt.Printf("longitude: %f\n", results.Longitude)fmt.Printf("domain: %s\n", results.Domain)fmt.Printf("zipcode: %s\n", results.Zipcode)fmt.Printf("timezone: %s\n", results.Timezone)fmt.Printf("netspeed: %s\n", speed)fmt.Printf("iddcode: %s\n", results.Iddcode)fmt.Printf("areacode: %s\n", results.Areacode)fmt.Printf("weatherstationcode: %s\n", results.Weatherstationcode)fmt.Printf("weatherstationname: %s\n", results.Weatherstationname)fmt.Printf("mcc: %s\n", results.Mcc)fmt.Printf("mnc: %s\n", results.Mnc)fmt.Printf("mobilebrand: %s\n", results.Mobilebrand)fmt.Printf("elevation: %f\n", results.Elevation)fmt.Printf("usagetype: %s\n", results.Usagetype)fmt.Printf("api version: %s\n", ip2location.Api_version())db.Close()}

实测运行效果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。