Get the location of iP and network operator
Applications used:7
Product services support payments in USD, HKD, and USDT
HTTP protocol:
http://api.youripapi.com/ipdata/
HTTPS protocol:
https://api.youripapi.com/ipdata/
* The API interface may be blocked due to various network reasons and attacks. Please make redundancy and exception handling during development
*If the status code returned by the HTTP request is not 200, perform an exception. For example, the status code 202 May be caused by invalid Token, insufficient balance, or incorrect format
iP query interface example for Golang:
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
)
const (
URL = "https://api.youripapi.com/ip/"
TOKEN = "bd4c2bf9a38ab06f7cae88c9759ee172"
)
//----------------------------------
// iP address call example code
//----------------------------------
// xml struct
type xmlinfo struct {
Ret string `xml:"ret"`
Ip string `xml:"ip"`
Data locationxmlInfo `xml:"data"`
}
type locationxmlInfo struct {
Country string `xml:"country"`
Region string `xml:"region"`
City string `xml:"city"`
Isp string `xml:"isp"`
Zip string `xml:"zip"`
Zone string `xml:zone`
}
//json struct
type jsoninfo struct {
Ret string `json:"ret"`
Ip string `json:"ip"`
Data [6]string `json:"data"`
}
func main() {
ipLocation("8.8.8.8","xml")
}
func ipLocation(iP string,dataType string) {
queryUrl := fmt.Sprintf("%s?ip=%s&datatype=%s",URL,ip,dataType)
client := &http.Client{}
reqest, err := http.NewRequest("GET",queryUrl,nil)
if err != nil {
fmt.Println("Fatal error ",err.Error())
}
reqest.Header.Add("token",TOKEN)
response, err := client.Do(reqest)
defer response.Body.Close()
if err != nil {
fmt.Println("Fatal error ",err.Error())
}
if response.StatusCode == 200 {
bodyByte, _ := ioutil.ReadAll(response.Body)
if dataType == "jsonp" {
var info jsoninfo
json.Unmarshal(bodyByte,&info)
fmt.Println(info.Ip)
} else if dataType == "xml" {
var info xmlinfo
xml.Unmarshal(bodyByte,&info)
fmt.Println(info.Ip)
}
}
return
}