账密认证
账密认证
账密DEMO示例
API认证
API获取
API DEMO示例
代理生成
账密DEMO示例
C/C++
Go
Java
Node.js
PHP
Python
#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://域名:端口");//设置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);
//不使用http代理
GetUrl("http://ipinfo.io", 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);
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://ipinfo.io/"
func main() {
getMyIp()
//账密
go httpProxy("ip:port", "账户", "密码")
go Socks5Proxy("ip:port", "账户", "密码")
time.Sleep(time.Minute)
}
func getMyIp() {
rsp, err := http.Get("https://ipinfo.io/")
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(time.Now().Format("2006-01-02 15:04:05 07"), "本机ip:", string(body))
}
//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", "返回信息:", 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.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, "返回信息:", 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】", "返回信息:", 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:3.10.0'
*/
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("代理地址", 8080));
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://ipinfo.io/";
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("代理地址", 8080));
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);
}
}
#!/usr/bin/env node
require('request-promise')({
url: 'https://ipinfo.io',
proxy: 'http://???-zone-custom:????@proxy.xxproxy.com:2333',
})
.then(function(data){ console.log(data); },
function(err){ console.error(err); });
// 要访问的目标页面
$targetUrl = "http://baidu.com";
// 代理服务器
$proxyServer = "http://proxy.xxproxy.com:2333";
$proxyUserPwd = ":";
// 隧道身份信息
$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);
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():
# 账密
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)
账密DEMO示例
C/C++
Go
Java
Node.js
PHP
Python
#include "iostream"
#include "curl/curl.h"
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main() {
CURL* curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://www.ipcool.net/app-api/getIp");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://ip:port");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
} else {
std::cout << readBuffer << std::endl;
}
curl_easy_cleanup(curl);
}
return 0;
}
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
func main() {
proxyUrl, _ := url.Parse("http://ip:port")
transport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
client := &http.Client{Transport: transport}
req, err := http.NewRequest("GET", "https://www.ipcool.net/app-api/getIp", nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println(string(body))
}
import java.io.*;
import java.net.*;
public class HttpClient {
public static void main(String[] args) {
try {
URL url = new URL("https://www.ipcool.net/app-api/getIp");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("ip", port));
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
connection.disconnect();
System.out.println(content.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
require('request-promise')({
url: 'https://www.ipcool.net/app-api/getIp',
proxy: 'http://ip:port',
})
.then(function(data){ console.log(data); },
function(err){ console.error(err); });
$proxy = "http://ip:port";
$url = "https://www.ipcool.net/app-api/getIp";
$options = [
"http" => [
"proxy" => $proxy,
"request_fulluri" => true,
],
];
$context = stream_context_create($options);
try {
$response = file_get_contents($url, false, $context);
echo $response;
} catch (Exception $e) {
echo $e->getMessage();
}
import requests
proxy = {"http": "http://ip:port", "https": "http://ip:port"}
url = "https://www.ipcool.net/app-api/getIp"
try:
response = requests.get(url, proxies=proxy)
print(response.text)
except requests.exceptions.RequestException as e:
print(e)