GO语言代理用法
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
//sock5代理
func socksproxy() {
urli := url.URL{}
urlproxy, _ := urli.Parse("http://测试ip:端口")
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(urlproxy),
},
}
rqt, err := http.NewRequest("GET", "http://myip.top", nil)
if err != nil {
println("接口获取IP失败!")
return
}
rqt.Header.Add("User-Agent", "Lingjiang")
//处理返回结果
response, _ := client.Do(rqt)
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return
}
fmt.Println("socks5:", string(body))
return
}
//http代理
func httpproxy() {
urli := url.URL{}
urlproxy, _ := urli.Parse("http://测试ip:端口")
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(urlproxy),
},
}
rqt, err := http.NewRequest("GET", "http://myip.top", nil)
if err != nil {
println("接口获取IP失败!")
return
}
rqt.Header.Add("User-Agent", "Lingjiang")
//处理返回结果
response, _ := client.Do(rqt)
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return
}
fmt.Println("http:", string(body))
return
}
//本机IP
func httplocal() {
client := &http.Client{}
rqt, err := http.NewRequest("GET", "http://myip.top", nil)
if err != nil {
println("接口获取IP失败!")
return
}
rqt.Header.Add("User-Agent", "Lingjiang")
//处理返回结果
response, _ := client.Do(rqt)
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return
}
fmt.Println("本机:", string(body))
return
}
func main() {
httplocal()
httpproxy()
socksproxy()
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。