注册
免费送1G流量

代码接入Demo

C++ Go PhantomJS Php Java Python Python-Selenium Node.js img

API提取

API获取 结果注释 返回结果示例 使用方法

C++语言

// 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)

{ //把接收的数据拷贝到缓存中

memcpy(outstream, buffer, nitems*size);

return nitems*size;

}

/*

使用http代理

*/

int GetUrlHTTP(char *url, char *buff)

{

CURL *curl;

CURLcode res;

curl = curl_easy_init();

if (curl)

{

curl_easy_setopt(curl, CURLOPT_PROXY,"http://测试ip:端口");//设置http代理地址

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://测试ip:端口");//设置socks5代理地址

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);

//不使用http代理

GetUrl("http://baidu.com", buff);

printf("不使用代理:%s\n", buff);

//使用http代理

memset(buff, 0, 1024 * 1024);

GetUrlHTTP("http://baidu.com", buff);

printf("http结果:%s\n", buff);

//使用socks5代理

memset(buff, 0,1024 * 1024);

GetUrlSocks5("http://baidu.com", buff);

printf("socks5结果:%s\n", buff);

 

 

Sleep(1000 * 1000);

free(buff);

return 0;

}

package main

 

import (

"fmt"

"golang.org/x/net/proxy"

"io/ioutil"

"net"

"net/http"

"net/url"

"os"

"time"

)

 

var testApi = "http://myip.top/"

 

func main() {

fmt.Println("代理测试")

 

go httpProxy("124.156.245.161", 10021)

 

go socks5Proxy("150.109.186.75", 6211)

 

time.Sleep(time.Hour)

}

 

func httpProxy(ip string, port int) {

defer func() {

if err := recover(); err != nil {

fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), "http", "返回信息:", err)

}

}()

urli := url.URL{}

urlproxy, _ := urli.Parse(fmt.Sprintf("http://%s:%d", ip, port))

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, err := ioutil.ReadAll(response.Body)

if err != nil {

panic(err)

return

}

fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), "http", "返回信息:", string(body))

return

}

 

func socks5Proxy(ip string, port int) {

dialer, err := proxy.SOCKS5("tcp", fmt.Sprintf("%s:%d", ip, port), nil, proxy.Direct)

if err != nil {

_, _ = fmt.Println("can't connect to the proxy:", err.Error())

os.Exit(1)

}

//setup a http client

httpClient := &http.Client{

Transport: &http.Transport{

Dial: func(network, addr string) (net.Conn, error) {

return dialer.Dial(network, addr)

},

},

}

httpClient.Timeout = time.Second * 10

// set our socks5 as the dialer

if resp, err := httpClient.Get(testApi); err != nil {

fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), "socks5", "返回信息:", err.Error())

} else {

defer resp.Body.Close()

body, _ := ioutil.ReadAll(resp.Body)

fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), "socks5", "返回信息:", string(body))

}

 

}

Phantomjs http/socks5:

 

phantomjs --proxy=ip:port --proxy-type=[http|socks5|none] demo.js

Php http/sock5:

 

// 要访问的目标页面

$targetUrl = "http://baidu.com";

 

// 代理服务器

$proxyServer = "http":"http://ip:port";

 

// 隧道身份信息

$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);

 

$result = curl_exec($ch);

 

curl_close($ch);

 

var_dump($result);

//http:

 

import org.apache.hc.client5.http.classic.methods.HttpGet;

import org.apache.hc.client5.http.config.RequestConfig;

import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;

import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;

import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;

import org.apache.hc.core5.http.HttpEntity;

import org.apache.hc.core5.http.HttpHost;

import org.apache.hc.core5.http.ParseException;

import org.apache.hc.core5.http.io.entity.EntityUtils;

 

import java.io.IOException;

import java.nio.charset.StandardCharsets;

 

/**

* Create by ipidea on 2021/2/6

*

* 依赖 compile 'org.apache.httpcomponents.client5:httpclient5:5.0.3'

*

* @see httpcomponents

*/

class HttpProxy {

public static void httpProxy() {

HttpGet request = new HttpGet("http://ky.myip.top/");

RequestConfig requestConfig = RequestConfig.custom()

.setProxy(new HttpHost("221.229.173.99", 13001))

.build();

request.setConfig(requestConfig);

 

try {

CloseableHttpClient httpClient = HttpClientBuilder.create()

.disableRedirectHandling()

.build();

CloseableHttpResponse response = httpClient.execute(request);

 

// Get HttpResponse Status

System.out.println(response.getVersion());

System.out.println(response.getCode());

System.out.println(response.getReasonPhrase());

 

HttpEntity entity = response.getEntity();

if (entity != null) {

// return it as a String

String result = EntityUtils.toString(entity, StandardCharsets.UTF_8);

System.out.println(result);

}

 

} catch (ParseException | IOException e) {

e.printStackTrace();

}

}

 

 

public static void main(String[] args) {

httpProxy();

}

}

 

//socks5

 

import org.apache.hc.client5.http.classic.methods.HttpGet;

import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;

import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;

import org.apache.hc.client5.http.impl.classic.HttpClients;

import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;

import org.apache.hc.client5.http.protocol.HttpClientContext;

import org.apache.hc.client5.http.socket.ConnectionSocketFactory;

import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;

import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;

import org.apache.hc.core5.http.HttpHost;

import org.apache.hc.core5.http.config.Registry;

import org.apache.hc.core5.http.config.RegistryBuilder;

import org.apache.hc.core5.http.io.entity.EntityUtils;

import org.apache.hc.core5.http.protocol.HttpContext;

import org.apache.hc.core5.ssl.SSLContexts;

import org.apache.hc.core5.util.TimeValue;

 

import javax.net.ssl.SSLContext;

import java.io.IOException;

import java.net.InetSocketAddress;

import java.net.Proxy;

import java.net.Socket;

import java.util.Map;

 

/**

* Create by ipidea on 2021/2/6

*

* 依赖 compile 'org.apache.httpcomponents.client5:httpclient5:5.0.3'

*

* @see httpcomponents

*/

class Socks5Proxy {

 

public static String socks5Proxy(String url, Map headers, String charset) {

 

Registry reg = RegistryBuilder.create()

.register("http", new MyConnectionSocketFactory())

.register("https", new MySSLConnectionSocketFactory(SSLContexts.createSystemDefault()))

.build();

PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg);

CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build();

try {

String proxyHost = "221.229.173.99";

int proxyPort = 13001;

 

InetSocketAddress socksAddr = new InetSocketAddress(proxyHost, proxyPort);

HttpClientContext context = HttpClientContext.create();

context.setAttribute("socks.address", socksAddr);

HttpGet httpget = new HttpGet(url);

if (headers != null) {

for (String key : headers.keySet()) {

httpget.setHeader(key, headers.get(key));

}

}

try (CloseableHttpResponse response = httpclient.execute(httpget, context)) {

return new String(EntityUtils.toByteArray(response.getEntity()), charset);

}

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

httpclient.close();

} catch (Exception e2) {

e2.printStackTrace();

}

}

return null;

}

 

static class MyConnectionSocketFactory extends PlainConnectionSocketFactory {

@Override

public Socket createSocket(final HttpContext context) {

InetSocketAddress socksAddr = (InetSocketAddress) context.getAttribute("socks.address");

Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksAddr);

return new Socket(proxy);

}

 

@Override

public Socket connectSocket(TimeValue connectTimeout, Socket socket, HttpHost host, InetSocketAddress remoteAddress,

InetSocketAddress localAddress, HttpContext context) throws IOException {

InetSocketAddress unresolvedRemote = InetSocketAddress

.createUnresolved(host.getHostName(), remoteAddress.getPort());

return super.connectSocket(connectTimeout, socket, host, unresolvedRemote, localAddress, context);

}

}

 

static class MySSLConnectionSocketFactory extends SSLConnectionSocketFactory {

 

public MySSLConnectionSocketFactory(final SSLContext sslContext) {

super(sslContext);

}

 

@Override

public Socket createSocket(final HttpContext context) throws IOException {

InetSocketAddress socksAddr = (InetSocketAddress) context.getAttribute("socks.address");

Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksAddr);

return new Socket(proxy);

}

 

@Override

public Socket connectSocket(TimeValue connectTimeout, Socket socket, HttpHost host,

InetSocketAddress remoteAddress, InetSocketAddress localAddress,

HttpContext context) throws IOException {

InetSocketAddress unresolvedRemote = InetSocketAddress

.createUnresolved(host.getHostName(), remoteAddress.getPort());

return super.connectSocket(connectTimeout, socket, host, unresolvedRemote, localAddress, context);

}

}

 

public static void main(String[] args) {

String msg = socks5Proxy("http://ky.myip.top/", null, "UTF-8");

System.out.println(msg);

 

}

}

#coding=utf-8

import requests

 

#请求地址

targetUrl = "https://www.baidu.com"

 

#代理服务器

proxyHost = "ip"

proxyPort = "port"

 

proxyMeta = "http://%(host)s:%(port)s" % {

 

"host" : proxyHost,

"port" : proxyPort,

}

 

#pip install -U requests[socks] socks5

# proxyMeta = "socks5://%(host)s:%(port)s" % {

 

# "host" : proxyHost,

 

# "port" : proxyPort,

 

# }

 

proxies = {

 

"http" : proxyMeta,

"https" : proxyMeta

}

 

resp = requests.get(targetUrl, proxies=proxies)

print resp.status_code

print resp.text

Python selenium http/socks5:

 

#coding=utf-8

from selenium import webdriver

 

# 代理服务器

proxyHost = "ip"

proxyPort = "port"

proxyType='http' #socks5

 

# 代理隧道验证信息

service_args = [

"--proxy-type=%s" % proxyType,

"--proxy=%(host)s:%(port)s" % {

"host" : proxyHost,

"port" : proxyPort,

}

]

 

# 要访问的目标页面

targetUrl = "http://baidu.com"

driver = webdriver.PhantomJS(service_args=service_args)

driver.get(targetUrl)

 

print driver.title

print driver.page_source.encode("utf-8")

driver.quit()

//node代理请求http

var http = require('http')

var opt = {

host: 'tunnel.alicloudecs.com',//这里放代理服务器的ip或者域名

port: '500',//这里放代理服务器的端口号

method: 'GET',//这里是发送的方法

path: 'http://www.sdip.321174.com/', //这里是访问的路径

}

//以下是接收数据的代码

var body = '';

var req = http.request(opt, function (res) {

console.log("Got response: " + res.statusCode);

res.on('data', function (d) {

body += d;

}).on('end', function () {

console.log(res.headers)

console.log(body)

});

 

}).on('error', function (e) {

console.log("Got error: " + e.message);

})

req.end();

 

 

 

//node代理请求http/https

const fetch = require("node-fetch");

const HttpsProxyAgent = require('https-proxy-agent');

//这里是访问的路径

let url="https://www.baidu.com/s?cl=3&tn=baidutop10&fr=top1000&wd=%E9%AB%98%E8%80%83&rsv_idx=2&rsv_dl=fyb_n_homepage&hisfilter=1";

//这是代理服务器地址

let ip='58.218.205.48';

//这是端口号

let port='500';

fetch(url, {

method: 'GET',

// body: null,

agent: new HttpsProxyAgent("http://" + ip + ":" + port) //<==注意是 `http://`

}).then(function (res) {

console.log("Response Headers ============ ");

res.headers.forEach(function(v,i,a) {

console.log(i+" : "+v);

});

return res.text();

}).then(function (res) {

console.log("Response Body ============ ");

console.log(res);

});

联系客服 联系客服联系客服 遇到问题?

微信客服

微信客服

189-0520-1785

客服二维码 扫一扫添加