123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- //go:build windows
- package yu_proxy
- import (
- yu_curl "gogs.qqck.cn/s/tools/curl"
- yu_json "gogs.qqck.cn/s/tools/json"
- yu_rand "gogs.qqck.cn/s/tools/rand"
- )
- var Internet_host, _ = yu_dns.ResolveIPS("im.qq.com")
- // Internet 是否可链接互联网
- // timeout 单位:毫秒
- func (t *Info) Internet(timeout int) bool {
- j_curl := yu_curl.NewRequest().SetRdirect(false).SetTimeout(timeout)
- defer j_curl.Close()
- // im.qq.com
- return j_curl.SetProxy(t.Encode()).Get("http://"+Internet_host[yu_rand.Intn(len(Internet_host))]).RespErr() == nil && j_curl.RespStatusCode() == 404
- }
- type AddrInfo struct {
- // 真实IP地址
- Ip string `json:"ip"`
- // 运营商
- Isp string `json:"isp"`
- // 省份
- Province string `json:"province"`
- // 城市
- City string `json:"city"`
- }
- func (t *AddrInfo) IsVaild() bool {
- return t.Ip != ""
- }
- // // Info (https://ip.useragentinfo.com/json)获取本机或指定代理IP的详细信息
- // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // // timeout 超时时间,单位:毫秒,0为默认的300s
- // func (t *Info) Info(timeout int) (info AddrInfo) {
- // if !t.IsValid() {
- // return
- // }
- // j_curl := yu_curl.NewRequest()
- // defer j_curl.Close()
- // // {"country": "中国", "short_name": "CN", "province": "河南省", "city": "郑州市", "area": "中原区", "isp": "电信", "net": "", "ip": "171.11.4.183", "code": 200, "desc": "success"}
- // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("https://ip.useragentinfo.com/json").RespErr() == nil {
- // j_json := yu_json.ParseBytes(j_curl.RespBody())
- // if j_json.Exists() {
- // info.Ip, info.Isp = j_json.Get("ip").String(), j_json.Get("isp").String()
- // info.Province, info.City = j_json.Get("province").String(), j_json.Get("city").String()
- // }
- // }
- // return
- // }
- // // InfoEx (http://ping0.cc/geojson)获取本机或指定代理IP的详细信息
- // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // // timeout 超时时间,单位:毫秒,0为默认的300s
- // func (t *Info) InfoEx(timeout int) (info AddrInfo) {
- // if !t.IsValid() {
- // return
- // }
- // j_curl := yu_curl.NewRequest()
- // defer j_curl.Close()
- // // {"ip":"171.11.4.255","location":"中国 河南省郑州市中原中国电信","country":"中国","province":"河南","city":"郑州","asn":"AS4134","org":"Chinanet HA","isidc":false,"iprisk":17}
- // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ping0.cc/geojson").RespErr() == nil {
- // j_json := yu_json.ParseBytes(j_curl.RespBody())
- // if j_json.Exists() {
- // info.Ip, info.Province, info.City = j_json.Get("ip").String(), j_json.Get("province").String(), j_json.Get("city").String()
- // }
- // }
- // return
- // }
- // var infoEx_host, _ = yu_dns.ResolveIPS("ping.huatuo.qq.com")
- //
- // func init() {
- // for j_i := 0; j_i < len(infoEx_host); j_i++ {
- // infoEx_host[j_i] = infoEx_host[j_i] + ":"
- // }
- // }
- //
- // // InfoEx2 (https://ping.huatuo.qq.com/index.php?btype=&userip=)获取本机或指定代理IP的详细信息
- // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // // timeout 超时时间,单位:毫秒,0为默认的300s
- // func (t *Info) InfoEx(timeout int) (info AddrInfo) {
- // if !t.IsValid() {
- // return
- // }
- // j_curl := yu_curl.NewRequest().SetConnectTo("ping.huatuo.qq.com:", infoEx_host[yu_rand.Intn(len(infoEx_host))])
- // defer j_curl.Close()
- // // {"code":0,"msg":"succ","data":{"ip":"1.193.82.33","isp":["\u4e2d\u56fd\u7535\u4fe1","\u6cb3\u5357\u7701","\u90d1\u5dde\u5e02"]}}
- // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("https://ping.huatuo.qq.com/index.php?btype=&userip=").RespErr() == nil {
- // j_json := yu_json.ParseBytes(j_curl.RespBody())
- // if j_json.Exists() {
- // info.Ip, info.Isp = j_json.Get("data.ip").String(), j_json.Get("data.isp.0").String()
- // info.Province, info.City = j_json.Get("data.isp.1").String(), j_json.Get("data.isp.2").String()
- // }
- // }
- // return
- // }
- // // InfoEx3 (http://ip-api.com/json)获取本机或指定代理IP的详细信息
- // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // // timeout 超时时间,单位:毫秒,0为默认的300s
- // func (t *Info) InfoEx2(timeout int) (info AddrInfo) {
- // if !t.IsValid() {
- // return
- // }
- // j_curl := yu_curl.NewRequest()
- // defer j_curl.Close()
- // // {
- // // "status": "success",
- // // "country": "China",
- // // "countryCode": "CN",
- // // "region": "HA",
- // // "regionName": "Henan",
- // // "city": "Zhengzhou",
- // // "zip": "",
- // // "lat": 34.7599,
- // // "lon": 113.6459,
- // // "timezone": "Asia/Shanghai",
- // // "isp": "CNC Group CHINA169 Henan Province Network",
- // // "org": "",
- // // "as": "AS4837 CHINA UNICOM China169 Backbone",
- // // "query": "219.155.116.243"
- // // }
- // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ip-api.com/json").RespErr() == nil {
- // j_json := yu_json.ParseBytes(j_curl.RespBody())
- // if j_json.Exists() {
- // info.Ip, info.Isp = j_json.Get("query").String(), j_json.Get("isp").String()
- // info.Province, info.City = j_json.Get("regionName").String(), j_json.Get("city").String()
- // }
- // }
- // return
- // }
- //
- // // InfoEx4 (http://whois.pconline.com.cn/ipJson.jsp?ip=&json=true)获取本机或指定代理IP的详细信息
- // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // // timeout 超时时间,单位:毫秒,0为默认的300s
- // func (t *Info) InfoEx3(timeout int) (info AddrInfo) {
- // if !t.IsValid() {
- // return
- // }
- // j_curl := yu_curl.NewRequest()
- // defer j_curl.Close()
- // // {"ip":"171.11.4.255","pro":"河南省","proCode":"410000","city":"郑州市","cityCode":"410100","region":"","regionCode":"0","addr":"河南省郑州市 电信","regionNames":"","err":""}
- // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://whois.pconline.com.cn/ipJson.jsp?ip=&json=true").RespErr() == nil {
- // j_json := yu_json.Parse(yu_strings.GbkToUtf8(j_curl.RespBodyS()))
- // if j_json.Exists() {
- // info.Ip, info.Province, info.City = j_json.Get("ip").String(), j_json.Get("pro").String(), j_json.Get("city").String()
- // }
- // }
- // return
- // }
- // InfoEx (http://ip-api.com/json/?lang=zh-CN)获取本机或指定代理IP的详细信息
- // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // timeout 超时时间,单位:毫秒,0为默认的300s
- func (t *Info) InfoEx(timeout int) (info AddrInfo) {
- if !t.IsValid() {
- return
- }
- j_curl := yu_curl.NewRequest()
- defer j_curl.Close()
- // http://ip-api.com/json/12.65.94.1?lang=zh-CN
- // {
- // "status": "success",
- // "country": "中国",
- // "countryCode": "CN",
- // "region": "HA",
- // "regionName": "河南",
- // "city": "郑州市",
- // "zip": "",
- // "lat": 34.7599,
- // "lon": 113.6459,
- // "timezone": "Asia/Shanghai",
- // "isp": "Chinanet",
- // "org": "Chinanet HA",
- // "as": "AS4134 CHINANET-BACKBONE",
- // "query": "171.11.4.255"
- // }
- if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ip-api.com/json/?lang=zh-CN").RespErr() == nil {
- j_json := yu_json.ParseBytes(j_curl.RespBody())
- if j_json.Exists() {
- info.Ip, info.Province, info.City = j_json.Get("query").String(), j_json.Get("regionName").String(), j_json.Get("city").String()
- }
- }
- return
- }
- // Info (http://myip.dnsomatic.com/)获取本机或指定代理IP的真实IP
- // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // timeout 超时时间,单位:毫秒,0为默认的300s
- // return
- // ip 真实IP地址
- func (t *Info) Info(timeout int) (ip string) {
- if !t.IsValid() {
- return
- }
- j_curl := yu_curl.NewRequest()
- defer j_curl.Close()
- if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://whatismyip.akamai.com/").RespErr() == nil {
- ip = j_curl.RespBodyS()
- }
- return
- }
- // // Info2 (http://ident.me/)获取本机或指定代理IP的真实IP
- // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
- // // timeout 超时时间,单位:毫秒,0为默认的300s
- // // return
- // // ip 真实IP地址
- // func (t *Info) Info2(timeout int) (ip string) {
- // if !t.IsValid() {
- // return
- // }
- // j_curl := yu_curl.NewRequest()
- // defer j_curl.Close()
- // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ident.me/").RespErr() == nil {
- // ip = j_curl.RespBodyS()
- // }
- // return
- // }
- // https://whois.pconline.com.cn/ipJson.jsp?ip=&json=true 是gbk编码,暂时不管
|