github.com/tickstep/library-go@v0.1.1/getip/getip_techain.go (about)

     1  package getip
     2  
     3  import (
     4  	"bytes"
     5  	"github.com/tickstep/library-go/requester"
     6  	"net/http"
     7  	"unsafe"
     8  )
     9  
    10  func IPInfoFromTechainBaiduByClient(c *requester.HTTPClient) (ipAddr string, err error) {
    11  	body, err := c.Fetch(http.MethodGet, "https://techain.baidu.com/srcmon", nil, map[string]string{
    12  		"User-Agent":      "x18/600000101/10.0.63/4.1.3",
    13  		"Pragma":          "no-cache",
    14  		"Accept":          "*/*",
    15  		"Content-Type":    "application/x-www-form-urlencoded",
    16  		"x-auth-ver":      "1",
    17  		"Accept-Language": "zh-CN",
    18  		"x-device-id":     "00000000000000000000000000000000",
    19  	})
    20  	if err != nil {
    21  		return
    22  	}
    23  	p := bytes.TrimSpace(body)
    24  	return *(*string)(unsafe.Pointer(&p)), nil
    25  }
    26  
    27  // IPInfoFromTechainBaidu 从 techain.baidu.com 获取ip
    28  func IPInfoFromTechainBaidu() (ipAddr string, err error) {
    29  	c := requester.NewHTTPClient()
    30  	return IPInfoFromNeteaseByClient(c)
    31  }