#include
#include
#include
#include
#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)
{
memcpy(outstream, buffer, nitems * size);
return nitems * size;
}
// http protocol
int GetHTTPFunc(char* url, char* buff)
{
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY, "http://hostname:port"); // hostname:port = us.shanhuhttp:3000
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "username:password"); // sub-account and password
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);
curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, 2000000L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK) {
return res;
}
else {
printf("http status code:%d", res);
MessageBox(NULL, TEXT("Get IP Error"), TEXT("assistant"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
// Socks5 protocol
int GetSocks5Func(char* url, char* buff)
{
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://hostname:port"); // hostname:port = us.shanhuhttp:3000
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "username:password"); //sub-account and password
curl_easy_setopt(curl, CURLOPT_SOCKS5_AUTH, CURLAUTH_SOCKS5_USERPWD);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data); // Callback
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);
curl_easy_setopt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, 2000000L);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK) {
return res;
}
else {
printf("status code:%d", res);
MessageBox(NULL, TEXT("Get IP Error"), TEXT("assistant"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
int func()
{
string strUrl = "ipinfo.io";
char* buff = (char*)malloc(1024 * 1024);
memset(buff, 0, 1024 * 1024);
//HTTP proxies
memset(buff, 0, 1024 * 1024);
GetHTTPFunc((char*)strUrl.c_str(), buff);
printf("Http results:%s", buff);
//Socks5 proxies
memset(buff, 0, 1024 * 1024);
GetSocks5Func((char*)strUrl.c_str(), buff);
printf("Socks5 result:%s", buff);
free(buff);
return 0;
}
int main()
{
return func();
}
package main
import (
"context"
"fmt"
"golang.org/x/net/proxy"
"io/ioutil"
"net"
"net/http"
"net/url"
"strings"
"time"
)
var ipInfoUrl = "https://ipinfo.io"
func main() {
var hostnamePort = "us.shanhuhttp:3000"
var username = "xxxx-region-US-sid-xrwfyi678-t-10" // xxxx = your sub-account
var password = "" // sub-account password
HttpProxy(proxyIP, username, password)
time.Sleep(time.Second * 1)
Socks5Proxy(proxyIP, username, password)
}
func HttpProxy(hostnamePort, username, password string) {
defer func() {
if err := recover(); err != nil {
fmt.Println(err)
}
}()
urli := url.URL{}
proxyUrl = fmt.Sprintf("http://%s", hostnamePort)
urlProxy, _ := urli.Parse(proxyUrl)
if username != "" && password != "" {
urlProxy.User = url.UserPassword(username, password)
}
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(urlProxy),
},
}
req, err := http.NewRequest("GET", ipInfoUrl, nil)
if err != nil {
panic(err)
return
}
response, err := client.Do(req)
if err != nil {
panic(err)
return
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
fmt.Println("http status = ", response.Status)
fmt.Println("content = ", string(body))
return
}
func Socks5Proxy(hostnamePort, username, password string) {
defer func() {
if err := recover(); err != nil {
fmt.Println(err)
}
}()
var userAuth proxy.Auth
if username != "" && password != "" {
userAuth.User = username
userAuth.Password = password
}
dialer, err := proxy.SOCKS5("tcp", proxyUrl, &userAuth, proxy.Direct)
if err != nil {
panic(err)
return
}
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,
}
resp, err := httpClient.Get(ipInfoUrl)
if err != nil {
panic(err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("content = ",string(body))
return
}
const SocksProxyAgent = require('socks-proxy-agent');
const net = require('net');
const proxyConfig = {
host: 'us.shanhuhttp.io',
port: 2000,
username: 'your sub-account username',
password: 'your sub-account password'
};
const agent = new SocksProxyAgent({
...proxyConfig,
});
const socket = net.connect({
host: 'ipinfo.io',
port: 80,
agent
});
socket.on('connect', () => {
console.log('Connect socks5 proxy.');
});
socket.on('error', err => {
console.log('error = ', err);
});
$targetUrl = "https://ipinfo.io/";
$proxyServer = "http://us.shanhuhttp:3000";
$proxyUserPwd = "username:password";
$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 protocol; sock5 protocolis is curl_setopt($ch, CURLOPT_PROXYTYPE, 5);
curl_setopt($ch, CURLOPT_PROXY, $proxyServer);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
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;
class AutProxyJava {
public static void main(String[] args) throws IOException {
testWithOkHttp();
testSocks5WithOkHttp();
}
public static void testWithOkHttp() throws IOException {
String url = "https://ipinfo.io";
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("us.shanhuhttp.io", 2000));
OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).proxyAuthenticator((route, response) -> {
String credential = Credentials.basic("subAccount-region-US", password); // update your sub-account and 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://ipinfo.io";
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("us.shanhuhttp.io", 2000));
java.net.Authenticator.setDefault(new java.net.Authenticator() {
private PasswordAuthentication authentication =
new PasswordAuthentication("sub account username", "sub account password".toCharArray()); // sub-account and password
@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 = "your sub-account username"
password = "your sub-account password"
ip = "us.shanhuhttp.io"
port = 2000
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://ipinfo.io/'
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)
print(response.read().decode('utf-8'))
except URLError as e:
print(e)