#include iostream
#include stdio.h
#include string
#include Windows.h
#include "curl/curl.h"
#pragma comment(lib, "libcurl.lib")
using namespace std;
static size_t write_buff_data(char* buffer, size_t size, size_t nitems, void* outstream)
{//Copy the received data to the cache
    memcpy(outstream, buffer, nitems * size);
    return nitems * size;
}
/*
Use HTTP proxy
*/
int GetUrlHTTP(char* url, char* buff)
{
    CURL* curl;
    CURLcode res;
    curl = curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_PROXY, "http://ip:port");//Set HTTP proxy address
        curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "User name: password");//Proxy username password
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);//Set Read-Write Cache
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);//Set Callback Function
        curl_easy_setopt(curl, CURLOPT_URL, url);//Set URL address
        curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);//Sets a long integer to control how many seconds CURLOPT_LOW_SPEED_LIMIT bytes are passed
        curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);//Set a long integer to control how many bytes are transferred
        curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, 2000000L);//Maximum download speed
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        if (res == CURLE_OK) {
            return res;
        }
        else {
            printf("error code:%d\n", res);
            MessageBox(NULL, TEXT("Get IP Error"), TEXT("assistant"), MB_ICONINFORMATION | MB_YESNO);
        }
    }
    return res;
}
                   
                  
                    package main
import (
    "context"
    "fmt"
    "golang.org/x/net/proxy"
    "io/ioutil"
    "net"
    "net/http"
    "net/url"
    "strings"
    "time"
)
var testApi = "https://api.ipify.org/?format=json"
func main() {
    var proxyIP = ""
    var username = "xxx-zone-isp"
    var password = ""
    httpProxy(proxyIP, username, password)
    time.Sleep(time.Second * 1)
    Socks5Proxy(proxyIP, username, password)
}
func httpProxy(proxyUrl, user, pass string) {
    defer func() {
        if err := recover(); err != nil {
            fmt.Println(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("http result = ", response.Status, string(body))
    return
}
func Socks5Proxy(proxyUrl, user, pass string) {
    defer func() {
        if err := recover(); err != nil {
            fmt.Println(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,
    }
    if resp, err := httpClient.Get(testApi); err != nil {
        panic(err)
    } else {
        defer resp.Body.Close()
        body, _ := ioutil.ReadAll(resp.Body)
        fmt.Println("socks5 result = ",string(body))
    }
}
                   
                  
                    const SocksProxyAgent = require("socks-proxy-agent");
const net = require("net");
const proxyHost = "proxy-server-hostname";
const proxyPort = 1080;
const proxyUsername = "your-username";
const proxyPassword = "your-password";
const agent = new SocksProxyAgent({
  host: proxyHost,
  port: proxyPort,
  auth: `${proxyUsername}:${proxyPassword}`
});
const socket = net.connect({
  host: "destination-hostname",
  port: 80,
  agent
});
socket.on("connect", () => {
  console.log("Connected to destination server through SOCKS5 proxy.");
});
socket.on("error", err => {
  console.error("Error:", err);
});
                   
                  
                    <?php
$targetUrl = "https://www.google.com/";
$proxyServer = "http://";
$proxyUserPwd = "user:psswd";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $targetUrl);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_PROXYTYPE, 0); //http
// curl_setopt($ch, CURLOPT_PROXYTYPE, 5); //sock5
curl_setopt($ch, CURLOPT_PROXY, $proxyServer);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyUserPwd);
$result = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
var_dump($err);
var_dump($result);
?>
                   
                  
                    package demo;
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
/**
* compile 'com.squareup.okhttp3:okhttp:3.10.0'
*/
class AutProxyJava {
    public static void main(String[] args) throws IOException {
        testWithOkHttp();
        testSocks5WithOkHttp();
    }
    public static void testWithOkHttp() throws IOException {
        String url = "https://api.ipify.org?format=json";
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("ip.proxys5.net", 6500));
        OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).proxyAuthenticator((route, response) -> {
            String credential = Credentials.basic("username-zone-custom", password);
                return response.request().newBuilder()
            .header("Proxy-Authorization", credential).build();
        }).build();
        Request request = new Request.Builder().url(url).build();
        okhttp3.Response response = client.newCall(request).execute();
        String responseString = response.body().string();
        System.out.println(responseString);
    }
    public static void testSocks5WithOkHttp() throws IOException {
        String url = "https://api.ipify.org?format=json";
        Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("ip.proxys5.net", 6500));
        java.net.Authenticator.setDefault(new java.net.Authenticator() {
            private PasswordAuthentication authentication =
            new PasswordAuthentication("laylay-zone-isp", "123456".toCharArray());
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return authentication;
            }
        });
        OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).build();
        Request request = new Request.Builder().url(url).build();
        okhttp3.Response response = client.newCall(request).execute();
        String responseString = response.body().string();
        System.out.println(responseString);
    }
}
                   
                  
                    import urllib
import socks
import http.client
from urllib.error import URLError
import ssl
from urllib.request import build_opener, HTTPHandler, HTTPSHandler
def merge_dict(a, b):
    d = a.copy()
    d.update(b)
    return d
class SocksiPyConnection(http.client.HTTPConnection):
    def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
        self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
        http.client.HTTPConnection.__init__(self, *args, **kwargs)
    def connect(self):
        self.sock = socks.socksocket()
        self.sock.setproxy(*self.proxyargs)
        if type(self.timeout) in (int, float):
            self.sock.settimeout(self.timeout)
        self.sock.connect((self.host, self.port))
class SocksiPyConnectionS(http.client.HTTPSConnection):
    def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
        self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
        http.client.HTTPSConnection.__init__(self, *args, **kwargs)
    def connect(self):
        sock = socks.socksocket()
        sock.setproxy(*self.proxyargs)
        if type(self.timeout) in (int, float):
            sock.settimeout(self.timeout)
        sock.connect((self.host, self.port))
        self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
class SocksiPyHandler(HTTPHandler, HTTPSHandler):
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kw = kwargs
        HTTPHandler.__init__(self)
    def http_open(self, req):
        def build(host, port=None, timeout=0, **kwargs):
            kw = merge_dict(self.kw, kwargs)
            conn = SocksiPyConnection(*self.args, host=host, port=port, timeout=timeout, **kw)
            return conn
        return self.do_open(build, req)
    def https_open(self, req):
        def build(host, port=None, timeout=0, **kwargs):
            kw = merge_dict(self.kw, kwargs)
            conn = SocksiPyConnectionS(*self.args, host=host, port=port, timeout=timeout, **kw)
            return conn
        return self.do_open(build, req)
username = ""
password = ""
ip = "ip.proxys5.net"
port = 6500
proxy = "socks5://{username}:{password}@{ip}:{port}".format(username=username, password=password, ip=ip, port=port)
# socks.set_default_proxy(socks.SOCKS5, ip, port,username=username,password=password)
# socket.socket = socks.socksocket
url = 'https://www.google.com/'
try:
    req = urllib.request.Request(url=url, headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'})
    opener = build_opener(SocksiPyHandler(socks.SOCKS5, ip, port, username=username, password=password))
    response = opener.open(req)
    # response = urllib.request.urlopen(req)
    # response = request.urlopen(url)
    print(response.read().decode('utf-8'))
except URLError as e:
    print(e)