#include "stdafx.h"
#include "curl/curl.h"
#pragma comment(lib, "libcurl.lib")
static size_t write_buff_data(char *buffer, size_t size, size_t nitems, void *outstream)
{
memcpy(outstream, buffer, nitems*size);
return nitems*size;
}
int GetUrlHTTP(char *url, char *buff)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY,"http://xxx.bitudaili.com:10000");
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "user: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("%d\\n", res);
}
}
return res;
}
int GetUrlSocks5(char *url, char *buff)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://xxx.bitudaili.com:port");
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "user: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("%d\\n", res);
}
}
return res;
}
int main()
{
char *buff=(char*)malloc(1024*1024);
memset(buff, 0, 1024 * 1024);
GetUrlHTTP("http://ipinfo.io", buff);
printf(" %s\\n", buff);
memset(buff, 0,1024 * 1024);
GetUrlSocks5("http://ipinfo.io", buff);
printf("%s\\n", buff);
free(buff);
Sleep(10 * 1000);
return 0;
}
package main
import (
"context"
"fmt"
"io"
"net"
"net/http"
"net/url"
"strings"
"time"
"golang.org/x/net/proxy"
)
var user = "your user"
var password = "your passwd"
var proxyServer = "proxyServer" //example:xxx.bitudaili.com:10000;
var target = "https://ipinfo.io"
func main() {
go httpProxy(proxyServer, user, password)
go Socks5Proxy(proxyServer, user, password)
time.Sleep(time.Minute)
}
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", "response:", 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", target, nil)
if err != nil {
panic(err)
}
response, err := client.Do(rqt)
if err != nil {
panic(err)
}
defer response.Body.Close()
body, _ := io.ReadAll(response.Body)
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), proxyUrl, "【http success】", "response:", response.Status, string(body))
return
}
// socks5
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, "response:", 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(target); err != nil {
panic(err)
} else {
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), proxyUrl, "【socks5 success】", "response:", string(body))
}
}
#!/usr/bin/env node
require('request-promise')({
url: 'https://ipinfo.io',
proxy: 'http://user-zone-custom:password@xxx.bitudaili.com:10000',
})
.then(function(data){ console.log(data); },
function(err){ console.error(err); });
<?php
$user = "user";
$password = "passswd";
$targetUrl = "https://ipinfo.io";
$proxyServer = "proxy server"; //Sakura;
$proxyUserPwd = "$user:$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
// 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:4.9.3'
*/
class AutProxyJava {
public static void main(String[] args) throws IOException {
testWithOkHttp();
testSocks5WithOkHttp();
}
/**
* http
*/
public static void testWithOkHttp() throws IOException {
String url = "https://ipinfo.io";
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", "port"));
OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).proxyAuthenticator((route, response) -> {
String credential = Credentials.basic("username", "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);
}
/**
* Socks5
*/
public static void testSocks5WithOkHttp() throws IOException {
String url = "https://ipinfo.io";
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("host", "port"));
java.net.Authenticator.setDefault(new java.net.Authenticator() {
private PasswordAuthentication authentication =
new PasswordAuthentication("username", "password".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 _thread
import time
import requests
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.19 NetType/4G Language/zh_CN",
}
target = "https://ipinfo.io"
def testUrl():
proxy = {
"http": "http://username:passwd@proxy_server:port",
"https": "http://username:passwd@proxy_server:port",
}
try:
res = requests.get(target, headers=headers, proxies=proxy, timeout=10)
print(res.status_code, res.text)
except Exception as e:
print(e)
pass
for i in range(0, 10):
_thread.start_new_thread(testUrl, ())
time.sleep(0.1)
time.sleep(10)