匯集全球200+國家地區(qū)的真實住宅IP,支持HTTP/HTTPS/SOCKS5代理協(xié)議,讓數(shù)據(jù)采集更簡單。
1000萬+IP
純凈住宅代理
200+國家地區(qū)
全球覆蓋
99.9%
高可用率
24/7
實時技術支持
Roxlabs代理高帶寬,IP資源池24小時去重,保障動態(tài)住宅代理快速運行,平均響應時間為0.6秒。技術團隊全程監(jiān)測系統(tǒng),客服團隊隨時解答用戶問題。
Roxlabs動態(tài)住宅支持1-1440分鐘自定義IP時效,可以根據(jù)業(yè)務需求自主設定會話時長。支持HTTP/HTTPS/SOCKS5代理協(xié)議,自由設置API提取導出格式。
Roxlabs個人中心實時統(tǒng)計代理使用數(shù)據(jù),您可以隨時查看賬戶余額信息和流量使用情況,支持添加多個IP白名單和認證賬戶,更有IP管理、認證賬戶管理等功能。
from selenium import webdriver
import requests
def seleniumSetUP(ip,port):
# 設置Chrome驅(qū)動程序的路徑
chromedriver_path = './chromedriver.exe'
# 創(chuàng)建Chrome瀏覽器實例
chrome_options = webdriver.ChromeOptions()
browser = webdriver.Chrome(chromedriver_path, chrome_options=chrome_options)
# 配置獲取到的ip和port
chrome_options.add_argument(f'--proxy-server=http://{ip}:{port}')
# 使用代理訪問
browser.get('http://ipinfo.io')
print(browser.page_source)
if __name__ == '__main__':
# 獲取代理的url,一次僅獲取一條
porxyUrl = "http://api.tq.roxlabs.cn/getProxyIp?num=1&return_type=txt&lb=1&sb=0&flow=1®ions=&protocol=http"
# 訪問并獲取代理
ipInfo = requests.get(porxyUrl)
info = ipInfo.json()["data"]
# 解析json,獲取代理服務器地址
ip = info[0]["ip"]
# 解析json,獲取代理的端口
port = info[0]["port"]
# 獲取到的代理信息傳入到selenium中進行配置
seleniumSetUP(ip,port)
# coding=utf-8
# !/usr/bin/env python
import json
import threading
import time
import requests as rq
# 設置請求頭
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate, br"
}
# 測試鏈接
testUrl = 'https://ipinfo.io'
# 核心業(yè)務
def testPost(host, port):
# 配置獲取到的ip,port
proxies = {
# host api獲取到的代理服務器地址
# port api獲取到的端口
'http': 'http://{}:{}'.format(host, port),
'https': 'http://{}:{}'.format(host, port),
}
while True:
try:
# 配置代理后測試
res = rq.get(testUrl, proxies=proxies, timeout=5)
# print(res.status_code)
# 打印請求結果
print(res.status_code, "***", res.text)
break
except Exception as e:
print(e)
break
return
class ThreadFactory(threading.Thread):
def __init__(self, host, port):
threading.Thread.__init__(self)
self.host = host
self.port = port
def run(self):
testPost(self.host, self.port)
# 提取代理的鏈接 json類型的返回值
tiqu = '提取鏈接'
while 1 == 1:
# 每次提取10個,放入線程中
resp = rq.get(url=tiqu, timeout=5)
try:
if resp.status_code == 200:
dataBean = json.loads(resp.text)
else:
print("獲取失敗")
time.sleep(1)
continue
except ValueError:
print("獲取失敗")
time.sleep(1)
continue
else:
# 解析json數(shù)組,獲取ip和port
print("code=", dataBean["code"])
code = dataBean["code"]
if code == 0:
threads = []
for proxy in dataBean["data"]:
threads.append(ThreadFactory(proxy["ip"], proxy["port"]))
for t in threads: # 開啟線程
t.start()
time.sleep(0.01)
for t in threads: # 阻塞線程
t.join()
# break
time.sleep(1)
#!/usr/bin/env node
require('request-promise')({
url: 'https://ipinfo.io',//請求url
proxy: 'http://ip:port',//代理服務器地址:端口
})
.then(function(data){ console.log(data); },
function(err){ console.error(err); });
<?php
//代理IP設置
$ip = "代理服務器地址";//示例:192.168.0.1
$port = "端口";//示例:4600
// 要訪問的目標頁面
$targetUrl = "http://baidu.com";
// 代理服務器
$proxyServer = "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);
$err = curl_error($ch);
curl_close($ch);
var_dump($err);
var_dump($result);
package main
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"strings"
"time"
"golang.org/x/net/proxy"
)
// 代理IP設置
var ip = "代理服務器" //示例:192.168.0.1
var port = "端口" //示例:4600
// 代理服務器
var proxyServer = "http://" + ip + ":" + port
// 測試地址
var testApi = "https://ipinfo.io"
func main() {
var proxyIP = proxyServer
go httpProxy(proxyIP, "", "")
go Socks5Proxy(proxyIP, "", "")
time.Sleep(time.Minute)
}
// http代理
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", 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(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(testApi); err != nil {
panic(err)
} else {
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), proxyUrl, "【socks5 success】", "response:", string(body))
}
}
package demo;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
/**
* compile 'com.squareup.okhttp3:okhttp:4.9.3'
*/
class ApiProxyJava {
public static void main(String[] args) throws IOException {
testHttpWithOkHttp();
testSocks5WithOkHttp();
}
/**
* http代理
*/
public static void testHttpWithOkHttp() throws IOException {
//定義要訪問的URL
String url = "https://ipinfo.io";
//創(chuàng)建一個HTTP類型的代理對象,設置代理服務器IP地址和端口號:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("ip", "port"));//這里的 "ip" 和 "port"應替換為代理服務器地址和端口。
//構建一個OkHttpClient實例,并配置好HTTP代理:
OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).build();
//發(fā)送GET請求并獲取響應:
Request request = new Request.Builder().url(url).build();
okhttp3.Response response = client.newCall(request).execute();
//獲取并打印響應內(nèi)容
String responseString = response.body().string();
System.out.println(responseString);
}
/**
* SOCKS5代理
*/
public static void testSocks5WithOkHttp() throws IOException {
//定義要訪問的URL
String url = "https://ipinfo.io";
//創(chuàng)建一個SOCKS類型的代理對象,設置代理服務器IP地址和端口號:
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("ip", "port"));//這里的 "ip" 和 "port"應替換為實際的SOCKS代理服務器地址和端口。
//構建一個OkHttpClient實例,并配置好SOCKS代理:
//這里使用了SOCKS代理,這意味著所有的網(wǎng)絡流量(包括TCP連接)都將通過這個SOCKS代理進行轉發(fā)。
OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).build();
//發(fā)送GET請求并獲取響應:
Request request = new Request.Builder().url(url).build();
okhttp3.Response response = client.newCall(request).execute();
//獲取并打印響應內(nèi)容:
String responseString = response.body().string();
System.out.println(responseString);
}
}
// demo.cpp : 定義控制臺應用程序的入口點。
//
#include "stdafx.h"
#include "curl/curl.h"
#pragma comment(lib, "libcurl.lib")
//在CURLOPT_WRITEFUNCTION設置屬性下,使用回調(diào)write_buff_data進行處理
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://代理服務器地址:端口");//設置代理
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);//void* buff 將會傳遞給回調(diào)函數(shù)write_buff_data的第四個參數(shù) void* outstream
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);//在CURLOPT_WRITEFUNCTION設置屬性下,使用回調(diào)write_buff_data進行處理
curl_easy_setopt(curl, CURLOPT_URL, url);//設置訪問的域名
/* 如果在10秒內(nèi)速度低于50個字節(jié)/秒,則中止 */
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);
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://代理服務器地址:端口");//設置代理
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);
MessageBox(NULL, TEXT("獲取IP錯誤"), TEXT("助手"), MB_ICONINFORMATION | MB_YESNO);
}
}
return res;
}
/*
不使用代理
*/
int GetUrl(char *url, char *buff)
{
CURL *curl;
CURLcode res;
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);
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);
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://baidu.com", buff);
printf("不使用代理:%s\n", buff);
memset(buff, 0, 1024 * 1024);
GetUrlHTTP("http://baidu.com", buff);
printf("http結果:%s\n", buff);
memset(buff, 0,1024 * 1024);
GetUrlSocks5("http://baidu.com", buff);
printf("socks5結果:%s\n", buff);
free(buff);
Sleep(10 * 1000);//等待10秒退出
return 0;
}
'''
注意:本方法需要安裝seleniumwire庫 pip install selenium-wire
其他情況下 可能需要配合selenium的webdriver使用 即selenium和seleniumwire都要導入
使用seleniumwire庫的目的就是減少代碼量和無意義的插件使用,方便快捷
'''
from seleniumwire import webdriver
# selenium-wire 代理設置
# username 用戶名
# password 密碼
# host 域名
# port 端口
seleniumwire_options = {
'proxy': {
'http': 'http://myusername:password@host:port',
'https': 'http://myusername:password@host:port',
'no_proxy': 'localhost,127.0.0.1'
}
}
# other Chrome options
chrome_options = webdriver.ChromeOptions()
# 設置無頭
chrome_options.add_argument('--headless')
# 忽視ssl報錯
chrome_options.add_argument('--ignore-ssl-errors')
driver = webdriver.Chrome('chromedriver', options=chrome_options, seleniumwire_options=seleniumwire_options)
driver.get('https://ipinfo.io')
'''
導入thread,time,request包,
實現(xiàn)多線程控制,等待,http請求
'''
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://ipinfo.io'
def testUrl():
# 設置帳密代理
proxy = {
'http': 'http://認證賬戶名:認證賬戶密碼@代理服務器地址:代理服務器端口',
'https': 'http://認證賬戶名:認證賬戶密碼@代理服務器地址:代理服務器端口',
}
try:
res = requests.get(mainUrl, headers=headers, proxies=proxy, timeout=10)
print(res.status_code, res.text)
except Exception as e:
print("訪問失敗", e)
pass
# 開啟10個線程進行測試
for i in range(0, 10):
_thread.start_new_thread(testUrl, ())
time.sleep(0.1)
time.sleep(10)
#!/usr/bin/env node
require('request-promise')({
url: 'https://ipinfo.io',//請求url
proxy: 'http://???:????@pr.roxlabs.cn:4600',//認證賬戶名:認證賬戶密碼@代理地址
})
.then(function(data){ console.log(data); },
function(err){ console.error(err); });
<?php
//賬密設置
$user = "認證帳戶名";
$password = "認證賬戶密碼";
// 要訪問的目標頁面
$targetUrl = "http://baidu.com";
// 代理服務器
$proxyServer = "代理地址"; //示例:xxx.pr.roxlabs.cn:4600;
$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 main
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"strings"
"time"
"golang.org/x/net/proxy"
)
// 賬密設置
var account = "認證帳戶名"
var password = "認證賬戶密碼"
// 代理服務器
var proxyServer = "代理地址" //示例:xxx.pr.roxlabs.cn:4600;
// 測試地址
var testApi = "https://ipinfo.io"
func main() {
go httpProxy(proxyServer, account, password)
go Socks5Proxy(proxyServer, account, password)
time.Sleep(time.Minute)
}
// http代理
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", 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(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(testApi); err != nil {
panic(err)
} else {
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(time.Now().Format("2006-01-02 15:04:05 07"), proxyUrl, "【socks5 success】", "response:", string(body))
}
}
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";//請求地址
//創(chuàng)建一個HTTP類型的代理對象,指定代理服務器的主機名和端口號
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", "port"));//這里用到的"host"和"port"應替換為代理服務器地址和端口。
// 構建一個自定義的OkHttpClient實例,設置代理服務器并添加一個代理認證器(proxyAuthenticator):
OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).proxyAuthenticator((route, response) -> {
// 在這里生成Basic認證的憑證字符串
String credential = Credentials.basic("account", "password");//此處的賬號密碼 "account" 和 "password" 應替換為認證賬戶名和認證賬戶密碼。
// 如果代理服務器需要身份驗證,則在請求頭中添加認證信息
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}).build();
//發(fā)送GET請求并獲取響應:
Request request = new Request.Builder().url(url).build();
okhttp3.Response response = client.newCall(request).execute();
//獲取并打印響應內(nèi)容:
String responseString = response.body().string();
System.out.println(responseString);
}
/**
* Socks5代理
*/
public static void testSocks5WithOkHttp() throws IOException {
//請求地址
String url = "https://ipinfo.io";
//創(chuàng)建一個SOCKS類型的代理對象,設置實際的代理服務器主機名和端口號:
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("host", "port"));//這里用到的"host"和"port"應替換為代理服務器地址和端口。
//設置全局默認的認證器(Authenticator),用于處理所有網(wǎng)絡連接需要的基本身份驗證。這里預設了一個用戶名和密碼:
java.net.Authenticator.setDefault(new java.net.Authenticator() {
private PasswordAuthentication authentication =
new PasswordAuthentication("account", "password".toCharArray());//此處的賬號密碼 "account" 和 "password" 應替換為認證賬戶名和認證賬戶密碼。
@Override
protected PasswordAuthentication getPasswordAuthentication()
});
//構建OkHttpClient實例,配置好SOCKS代理:
OkHttpClient client = new OkHttpClient().newBuilder().proxy(proxy).build();
//發(fā)送GET請求并獲取響應:
Request request = new Request.Builder().url(url).build();
okhttp3.Response response = client.newCall(request).execute();
//獲取并打印響應內(nèi)容:
String responseString = response.body().string();
System.out.println(responseString);
}
}
// demo.cpp : 定義控制臺應用程序的入口點。
//
#include "stdafx.h"
#include "curl/curl.h"
#pragma comment(lib, "libcurl.lib")
//curl 回調(diào)函數(shù)
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://代理服務器地址:端口");//設置http代理地址
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "認證賬戶名:認證賬戶密碼");//認證賬戶名及密碼,以":"分隔
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buff);//設置讀寫緩存
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buff_data);//設置回調(diào)函數(shù)
curl_easy_setopt(curl, CURLOPT_URL, url);//設置url地址
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);//設置一個長整形數(shù),控制多少秒傳送CURLOPT_LOW_SPEED_LIMIT規(guī)定的字節(jié)數(shù)
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);//設置一個長整形數(shù),控制傳送多少字節(jié)
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);//設置回調(diào)函數(shù)
curl_easy_setopt(curl, CURLOPT_URL, url);//設置url地址
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);//設置一個長整形數(shù),控制多少秒傳送CURLOPT_LOW_SPEED_LIMIT規(guī)定的字節(jié)數(shù)
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);//設置一個長整形數(shù),控制傳送多少字節(jié);
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);//設置回調(diào)函數(shù)
curl_easy_setopt(curl, CURLOPT_URL, url);//設置url地址
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L);//設置一個長整形數(shù),控制多少秒傳送CURLOPT_LOW_SPEED_LIMIT規(guī)定的字節(jié)數(shù)
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 50L);//設置一個長整形數(shù),控制傳送多少字節(jié)
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://myip.top", buff);
printf("不使用代理:%s\n", buff);
//使用http代理
memset(buff, 0, 1024 * 1024);
GetUrlHTTP("http://ipinfo.io", buff);
printf("http結果:%s\n", buff);
//使用socks5代理
memset(buff, 0,1024 * 1024);
GetUrlSocks5("http://ipinfo.io", buff);
printf("socks5結果:%s\n", buff);
free(buff);
Sleep(10 * 1000);//等待10秒退出
return 0;
}
純凈動態(tài)住宅
獨享靜態(tài)IP
流量不過期
城市級定位
無限并發(fā)
支持HTTP(S)/Socks5協(xié)議