Exemplo n.º 1
0
func testIp(ipAddr string) {
	ipinfo, err := iploc.GetIpInfo(ipAddr)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(ipAddr)

	switch ipinfo.Flag {
	case iploc.FLAG_INUSE:
		if ipinfo.Code == "CN" {
			fmt.Println(ipinfo.Code)
			fmt.Println(ipinfo.Country)
			fmt.Println(ipinfo.Region)
			fmt.Println(ipinfo.City)
			fmt.Println(ipinfo.Isp)
		} else {
			fmt.Println(ipinfo.Code)
			fmt.Println(ipinfo.Country)
		}
	case iploc.FLAG_RESERVED:
		fmt.Println(ipinfo.Note)
	case iploc.FLAG_NOTUSE:
		fmt.Println(ipinfo.Note)
	}

	for i := 0; i < 30; i++ {
		fmt.Print("-")
	}
	fmt.Print("\n")
}
Exemplo n.º 2
0
func (m *MainController) Post() {
	result := map[string]interface{}{"success": false}
	ip := m.Ctx.Request.Form.Get("ip")
	ipinfo, err := iploc.GetIpInfo(ip)
	if err != nil {
		result["msg"] = err.Error()
	} else {
		result["success"] = true
		result["ip"] = ip
		result["flag"] = ipinfo.Flag
		result["code"] = ipinfo.Code
		result["country"] = ipinfo.Country
		result["region"] = ipinfo.Region
		result["city"] = ipinfo.City
		result["isp"] = ipinfo.Isp
		if ipinfo.Flag != iploc.FLAG_INUSE {
			result["note"] = ipinfo.Note
		}
	}
	m.Data["json"] = result
	m.ServeJson()
}
Exemplo n.º 3
0
func testSpeed() {
	r := Benchmark(func(b *B) {
		ips := []string{
			"0.0.0.0",
			"127.0.0.1",
			"169.254.0.1",
			"192.168.1.1",
			"10.0.0.0",
			"255.255.255.255",
			"112.226.155.1",
			"121.18.72.0",
			"6.18.72.0",
			"200.18.72.0",
		}
		for i := 0; i < b.N; i++ {
			for _, ipAddr := range ips {
				iploc.GetIpInfo(ipAddr)
			}
		}
	})
	fmt.Println(r)
	fmt.Printf("10w次查询: %.1f 毫秒\n", float64(r.NsPerOp())/100000000*1000*100000/10)
}