Mail:
200M+ ethically sourced Residential IPs, Free geo-targeting
Starts from
$0.77/GB
Unlimited Residential Proxy
Unlimited use of residential proxy traffic. Dedicated servers & IP pools!
Starts from
$79/Day
Dedicated Datacenter Proxy
Individual Dedicated IP, Availability > 99 %, Response Time 0.6S
Starts from
$2.5/IP/week
Static Residential Proxy
Combines the authenticity of a residential IP with the speed of a datacenter
Starts from
$3/IP/week
200M+ secure residential proxy offering high anonymity and low detection rates.
Unlimited Residential Proxy
Enjoy unlimited residential proxy usage with flexible IP rotation and session control.
Dedicated Datacenter Proxy
Secure datacenter proxies provide dedicated IP for stable, fast connections.
Static Residential Proxy
High-quality static residential proxies provide continuous, unchanged IP addresses.
< Back to blog
package main
import (
"context"
"fmt"
"golang.org/x/net/proxy"
"io/ioutil"
"net"
"net/http"
"net/url"
"strings"
"time"
)
var testApi = "https://api.myip.la/en?json"
func main() {
getMyIp()
//Accounts
var proxyIP = "ip:port"
go httpProxy(proxyIP, "", "")
go Socks5Proxy(proxyIP, "", "")
time.Sleep(time.Minute)
}
func getMyIp() {
rsp, err := http.Get("https://api.myip.la/en?json")
if err != nil {
fmt.Println("Failed to get native IP", err.Error())
return
}
defer rsp.Body.Close()
body, err := ioutil.ReadAll(rsp.Body)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), "local ip:", string(body))
}
//http proxy
func httpProxy(proxyUrl, user, pass string) {
defer func() {
if err := recover(); err != nil {
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), "http", "Return information:", err)
}
}()
urli := url.URL{}
if !strings.Contains(proxyUrl, "http") {
proxyUrl = fmt.Sprintf("http://%s", proxyUrl)
}
urlProxy, _ := urli.Parse(proxyUrl)
if user != "" && pass != "" {
urlProxy.User = url.UserPassword(user, pass)
}
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(urlProxy),
},
}
rqt, err := http.NewRequest("GET", testApi, nil)
if err != nil {
panic(err)
return
}
response, err := client.Do(rqt)
if err != nil {
panic(err)
return
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), proxyUrl, "【http success】", "Return information:", response.Status, string(body))
return
}
//Socks5 proxy
func Socks5Proxy(proxyUrl, user, pass string) {
defer func() {
if err := recover(); err != nil {
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), proxyUrl, " Return information:", err)
}
}()
var userAuth proxy.Auth
if user != "" && pass != "" {
userAuth.User = user
userAuth.Password = pass
}
dialer, err := proxy.SOCKS5("tcp", proxyUrl, &userAuth, proxy.Direct)
if err != nil {
panic(err)
}
httpClient := &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (conn net.Conn, err error) {
return dialer.Dial(network, addr)
},
},
Timeout: time.Second * 10,
}
//Request Network
if resp, err := httpClient.Get(testApi); err != nil {
panic(err)
} else {
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), proxyUrl, "【socks5 success】", " Return information:", string(body))
}
}
Forget about complex web scraping processesChoose
Tabproxy advanced web intelligence collectiosolutions to gather real-time public data hassle-free