微信扫一扫 联系专属客户经理
// demo.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "curl/curl.h"
#pragma comment(lib, "libcurl.lib")
//curl 回调函数
static size_t write_buff_data(char *buffer, size_t size, size_t nitems, void *outstream)
/*
使用数据代理
*/
int GetUrlHTTP(char *url, char *buff)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY,"http://域名:端口");//设置数据代理地址
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "用户名:密码");//代理用户名密码,以":"分隔用户名以及密码
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);//设置读写缓存
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);//设置回调函数
curl_easy_setopt(curl, CURLOPT_URL, url);//设置url地址
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);//设置一个长整形数,管理多少秒传送CURLOPT_LOW_SPEED_LIMIT规定的字节数
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);
MessageBox(NULL, TEXT("获取IP错误"), TEXT("助手"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
/*
使用socks5代理
*/
int GetUrlSocks5(char *url, char *buff)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_PROXY, "socks5://域名:端口");//设置socks5代理地址
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "用户名:密码");//代理用户名密码,以":"分隔用户名以及密码
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);//设置读写缓存
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);//设置回调函数
curl_easy_setopt(curl, CURLOPT_URL, url);//设置url地址
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);//设置一个长整形数,管理多少秒传送CURLOPT_LOW_SPEED_LIMIT规定的字节数
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);
MessageBox(NULL, TEXT("获取IP错误"), TEXT("助手"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
/*
不使用代理
*/
int GetUrl(char *url, char *buff)
{
CURL *curl;
CURLcode res;
//使用的curl库 初始化curl库
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);//设置读写缓存
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);//设置回调函数
curl_easy_setopt(curl, CURLOPT_URL, url);//设置url地址
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);//设置一个长整形数,管理多少秒传送CURLOPT_LOW_SPEED_LIMIT规定的字节数
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);
MessageBox(NULL, TEXT("获取IP错误"), TEXT("助手"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
int main()
{
char *buff=(char*)malloc(1024*1024);
memset(buff, 0, 1024 * 1024);
//不使用数据代理
GetUrl("http://myip.top", buff);
printf("不使用代理:%s\n", buff);
//使用数据代理
memset(buff, 0, 1024 * 1024);
GetUrlHTTP("http://myip.top", buff);
printf("http结果:%s\n", buff);
//使用socks5代理
memset(buff, 0,1024 * 1024);
GetUrlSocks5("http://myip.top", buff);
printf("socks5结果:%s\n", buff);
Sleep(1000 * 1000);
free(buff);
return 0;
}
package main
import (
"context"
"fmt"
"golang.org/x/net/proxy"
"io/ioutil"
"net"
"net/http"
"net/url"
"strings"
"time"
)
var testApi = "https://myip.top"
func main() {
getMyIp()
//账密
go httpProxy("ip:port", "账户", "密码")
go Socks5Proxy("ip:port", "账户", "密码")
time.Sleep(time.Minute)
}
func getMyIp() {
rsp, err := http.Get("https://myip.top")
if err != nil {
fmt.Println("获取本机ip失败", err.Error())
return
}
defer rsp.Body.Close()
body, err := ioutil.ReadAll(rsp.Body)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println("ip:", string(body))
}
//数据代理
func httpProxy(proxyUrl, user, pass string) {
defer func() {
if err := recover(); err != nil {
fmt.Println("http----error:", 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----success:", string(body))
return
}
//socks5代理
func Socks5Proxy(proxyUrl, user, pass string) {
defer func() {
if err := recover(); err != nil {
fmt.Println("socks5----error:", 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----success:", string(body))
}
}
#!/usr/bin/env node
require('request-promise')({
url: 'https://myip.top',
proxy: 'http://账号:密码@域名:端口',
})
.then(function(data){ console.log(data); },
function(err){ console.error(err); });
// 要访问的目标页面
$targetUrl = "http://baidu.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://myip.top";
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("140.249.73.234", 15021));
OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).proxyAuthenticator((route, response) -> {
String credential = Credentials.basic("账户", "密码");
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://myip.top";
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("140.249.73.234", 15021));
java.net.Authenticator.setDefault(new java.net.Authenticator() {
private PasswordAuthentication authentication =
new PasswordAuthentication("账户", "密码".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_TW",
}
mainUrl = 'https://myip.top'
def testUrl():
# 账密
entry = 'http://{}:{}@ip:port'.format("账户", "密码")
proxy = {
'http': entry,
'https': entry,
}
try:
res = requests.get(mainUrl, headers=headers, proxies=proxy, timeout=10)
print(res.status_code, res.text)
except Exception as e:
print("访问失败", e)
pass
for port in range(0, 10):
_thread.start_new_thread(testUrl, ())
time.sleep(0.1)
time.sleep(10)