info_windows.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //go:build windows
  2. package yu_proxy
  3. import (
  4. yu_curl "gogs.qqck.cn/s/tools/curl"
  5. yu_json "gogs.qqck.cn/s/tools/json"
  6. yu_rand "gogs.qqck.cn/s/tools/rand"
  7. )
  8. var Internet_host, _ = yu_dns.ResolveIPS("im.qq.com")
  9. // Internet 是否可链接互联网
  10. // timeout 单位:毫秒
  11. func (t *Info) Internet(timeout int) bool {
  12. j_curl := yu_curl.NewRequest().SetRdirect(false).SetTimeout(timeout)
  13. defer j_curl.Close()
  14. // im.qq.com
  15. return j_curl.SetProxy(t.Encode()).Get("http://"+Internet_host[yu_rand.Intn(len(Internet_host))]).RespErr() == nil && j_curl.RespStatusCode() == 404
  16. }
  17. type AddrInfo struct {
  18. // 真实IP地址
  19. Ip string `json:"ip"`
  20. // 运营商
  21. Isp string `json:"isp"`
  22. // 省份
  23. Province string `json:"province"`
  24. // 城市
  25. City string `json:"city"`
  26. }
  27. func (t *AddrInfo) IsVaild() bool {
  28. return t.Ip != ""
  29. }
  30. // // Info (https://ip.useragentinfo.com/json)获取本机或指定代理IP的详细信息
  31. // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  32. // // timeout 超时时间,单位:毫秒,0为默认的300s
  33. // func (t *Info) Info(timeout int) (info AddrInfo) {
  34. // if !t.IsValid() {
  35. // return
  36. // }
  37. // j_curl := yu_curl.NewRequest()
  38. // defer j_curl.Close()
  39. // // {"country": "中国", "short_name": "CN", "province": "河南省", "city": "郑州市", "area": "中原区", "isp": "电信", "net": "", "ip": "171.11.4.183", "code": 200, "desc": "success"}
  40. // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("https://ip.useragentinfo.com/json").RespErr() == nil {
  41. // j_json := yu_json.ParseBytes(j_curl.RespBody())
  42. // if j_json.Exists() {
  43. // info.Ip, info.Isp = j_json.Get("ip").String(), j_json.Get("isp").String()
  44. // info.Province, info.City = j_json.Get("province").String(), j_json.Get("city").String()
  45. // }
  46. // }
  47. // return
  48. // }
  49. // // InfoEx (http://ping0.cc/geojson)获取本机或指定代理IP的详细信息
  50. // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  51. // // timeout 超时时间,单位:毫秒,0为默认的300s
  52. // func (t *Info) InfoEx(timeout int) (info AddrInfo) {
  53. // if !t.IsValid() {
  54. // return
  55. // }
  56. // j_curl := yu_curl.NewRequest()
  57. // defer j_curl.Close()
  58. // // {"ip":"171.11.4.255","location":"中国 河南省郑州市中原中国电信","country":"中国","province":"河南","city":"郑州","asn":"AS4134","org":"Chinanet HA","isidc":false,"iprisk":17}
  59. // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ping0.cc/geojson").RespErr() == nil {
  60. // j_json := yu_json.ParseBytes(j_curl.RespBody())
  61. // if j_json.Exists() {
  62. // info.Ip, info.Province, info.City = j_json.Get("ip").String(), j_json.Get("province").String(), j_json.Get("city").String()
  63. // }
  64. // }
  65. // return
  66. // }
  67. // var infoEx_host, _ = yu_dns.ResolveIPS("ping.huatuo.qq.com")
  68. //
  69. // func init() {
  70. // for j_i := 0; j_i < len(infoEx_host); j_i++ {
  71. // infoEx_host[j_i] = infoEx_host[j_i] + ":"
  72. // }
  73. // }
  74. //
  75. // // InfoEx2 (https://ping.huatuo.qq.com/index.php?btype=&userip=)获取本机或指定代理IP的详细信息
  76. // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  77. // // timeout 超时时间,单位:毫秒,0为默认的300s
  78. // func (t *Info) InfoEx(timeout int) (info AddrInfo) {
  79. // if !t.IsValid() {
  80. // return
  81. // }
  82. // j_curl := yu_curl.NewRequest().SetConnectTo("ping.huatuo.qq.com:", infoEx_host[yu_rand.Intn(len(infoEx_host))])
  83. // defer j_curl.Close()
  84. // // {"code":0,"msg":"succ","data":{"ip":"1.193.82.33","isp":["\u4e2d\u56fd\u7535\u4fe1","\u6cb3\u5357\u7701","\u90d1\u5dde\u5e02"]}}
  85. // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("https://ping.huatuo.qq.com/index.php?btype=&userip=").RespErr() == nil {
  86. // j_json := yu_json.ParseBytes(j_curl.RespBody())
  87. // if j_json.Exists() {
  88. // info.Ip, info.Isp = j_json.Get("data.ip").String(), j_json.Get("data.isp.0").String()
  89. // info.Province, info.City = j_json.Get("data.isp.1").String(), j_json.Get("data.isp.2").String()
  90. // }
  91. // }
  92. // return
  93. // }
  94. // // InfoEx3 (http://ip-api.com/json)获取本机或指定代理IP的详细信息
  95. // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  96. // // timeout 超时时间,单位:毫秒,0为默认的300s
  97. // func (t *Info) InfoEx2(timeout int) (info AddrInfo) {
  98. // if !t.IsValid() {
  99. // return
  100. // }
  101. // j_curl := yu_curl.NewRequest()
  102. // defer j_curl.Close()
  103. // // {
  104. // // "status": "success",
  105. // // "country": "China",
  106. // // "countryCode": "CN",
  107. // // "region": "HA",
  108. // // "regionName": "Henan",
  109. // // "city": "Zhengzhou",
  110. // // "zip": "",
  111. // // "lat": 34.7599,
  112. // // "lon": 113.6459,
  113. // // "timezone": "Asia/Shanghai",
  114. // // "isp": "CNC Group CHINA169 Henan Province Network",
  115. // // "org": "",
  116. // // "as": "AS4837 CHINA UNICOM China169 Backbone",
  117. // // "query": "219.155.116.243"
  118. // // }
  119. // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ip-api.com/json").RespErr() == nil {
  120. // j_json := yu_json.ParseBytes(j_curl.RespBody())
  121. // if j_json.Exists() {
  122. // info.Ip, info.Isp = j_json.Get("query").String(), j_json.Get("isp").String()
  123. // info.Province, info.City = j_json.Get("regionName").String(), j_json.Get("city").String()
  124. // }
  125. // }
  126. // return
  127. // }
  128. //
  129. // // InfoEx4 (http://whois.pconline.com.cn/ipJson.jsp?ip=&json=true)获取本机或指定代理IP的详细信息
  130. // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  131. // // timeout 超时时间,单位:毫秒,0为默认的300s
  132. // func (t *Info) InfoEx3(timeout int) (info AddrInfo) {
  133. // if !t.IsValid() {
  134. // return
  135. // }
  136. // j_curl := yu_curl.NewRequest()
  137. // defer j_curl.Close()
  138. // // {"ip":"171.11.4.255","pro":"河南省","proCode":"410000","city":"郑州市","cityCode":"410100","region":"","regionCode":"0","addr":"河南省郑州市 电信","regionNames":"","err":""}
  139. // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://whois.pconline.com.cn/ipJson.jsp?ip=&json=true").RespErr() == nil {
  140. // j_json := yu_json.Parse(yu_strings.GbkToUtf8(j_curl.RespBodyS()))
  141. // if j_json.Exists() {
  142. // info.Ip, info.Province, info.City = j_json.Get("ip").String(), j_json.Get("pro").String(), j_json.Get("city").String()
  143. // }
  144. // }
  145. // return
  146. // }
  147. // InfoEx (http://ip-api.com/json/?lang=zh-CN)获取本机或指定代理IP的详细信息
  148. // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  149. // timeout 超时时间,单位:毫秒,0为默认的300s
  150. func (t *Info) InfoEx(timeout int) (info AddrInfo) {
  151. if !t.IsValid() {
  152. return
  153. }
  154. j_curl := yu_curl.NewRequest()
  155. defer j_curl.Close()
  156. // http://ip-api.com/json/12.65.94.1?lang=zh-CN
  157. // {
  158. // "status": "success",
  159. // "country": "中国",
  160. // "countryCode": "CN",
  161. // "region": "HA",
  162. // "regionName": "河南",
  163. // "city": "郑州市",
  164. // "zip": "",
  165. // "lat": 34.7599,
  166. // "lon": 113.6459,
  167. // "timezone": "Asia/Shanghai",
  168. // "isp": "Chinanet",
  169. // "org": "Chinanet HA",
  170. // "as": "AS4134 CHINANET-BACKBONE",
  171. // "query": "171.11.4.255"
  172. // }
  173. if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ip-api.com/json/?lang=zh-CN").RespErr() == nil {
  174. j_json := yu_json.ParseBytes(j_curl.RespBody())
  175. if j_json.Exists() {
  176. info.Ip, info.Province, info.City = j_json.Get("query").String(), j_json.Get("regionName").String(), j_json.Get("city").String()
  177. }
  178. }
  179. return
  180. }
  181. // Info (http://myip.dnsomatic.com/)获取本机或指定代理IP的真实IP
  182. // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  183. // timeout 超时时间,单位:毫秒,0为默认的300s
  184. // return
  185. // ip 真实IP地址
  186. func (t *Info) Info(timeout int) (ip string) {
  187. if !t.IsValid() {
  188. return
  189. }
  190. j_curl := yu_curl.NewRequest()
  191. defer j_curl.Close()
  192. if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://whatismyip.akamai.com/").RespErr() == nil {
  193. ip = j_curl.RespBodyS()
  194. }
  195. return
  196. }
  197. // // Info2 (http://ident.me/)获取本机或指定代理IP的真实IP
  198. // // info "ProxyType://user:pass@host:port" || "" ,例如:"Http://user:pass@127.0.0.1:808"、"Socks5://user:pass@127.0.0.1:808"
  199. // // timeout 超时时间,单位:毫秒,0为默认的300s
  200. // // return
  201. // // ip 真实IP地址
  202. // func (t *Info) Info2(timeout int) (ip string) {
  203. // if !t.IsValid() {
  204. // return
  205. // }
  206. // j_curl := yu_curl.NewRequest()
  207. // defer j_curl.Close()
  208. // if j_curl.SetProxy(t.Encode()).SetTimeout(timeout).Get("http://ident.me/").RespErr() == nil {
  209. // ip = j_curl.RespBodyS()
  210. // }
  211. // return
  212. // }
  213. // https://whois.pconline.com.cn/ipJson.jsp?ip=&json=true 是gbk编码,暂时不管