How to Use PrivateProxy.me Backconnect Proxy

如何使用 PrivateProxy.me Backconnect 代理服务器

您知道如何使用 PrivateProxy.me Backconnect Proxy? This is the most comprehensive introduction from PrivateProxy.me official.

不同语言的用法示例

在 *nix shell 中使用 curlPython 3 + 请求PHP + libcurlNode.js + stdlibRuby + stdlibGolang + stdlibC# + stdlib
curl -x http://login:[email protected]:5432 http://api.privateproxy.me:10738 #1.1.1.1
import requests
proxies = {
  'http': 'http://login:[email protected]:5432',
  'https': 'http://login:[email protected]:5432'
}
response = requests.get('http://api.privateproxy.me:10738', proxies=proxies)
// response.text = "1.1.1.1\\n"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://api.privateproxy.me:10738");
curl_setopt($ch, CURLOPT_PROXY, "1.1.1.1:5432");
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "login:password");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page; // "1.1.1.1\\n"
const http = require('http');
const https = require('https');

function getWithProxy(url, proxy) {
  const parsedUrl = new URL(url);
  const proxy_ip = proxy['ip']
  const proxy_port = proxy['port']
  const proxy_auth = 'Basic ' + Buffer.from(proxy['login'] + ':' + proxy['password']).toString('base64')

  let host = parsedUrl.hostname;
  if (parsedUrl.port !== '') {
    host += ':' + parsedUrl.port;
  } else {
    if (parsedUrl.protocol == 'http:') {
      host += ':80';
    } else if(parsedUrl.protocol == 'https:') {
      host += ':443';
    }
  }
  const res = new Promise((resolve, reject) => {
    http.request({
      port:   proxy_port,
      host:   proxy_ip,
      method: 'CONNECT',
      path:   host,
      headers: {
        'Host': host,
        'Proxy-Authorization': proxy_auth
      }
    }).on('connect', (res, socket, head) => {
      if (res.statusCode !== 200) {
        reject(new Error(`Non-200 status code returned from proxy: ${res.statusCode} ${res.statusMessage}`));
        return;
      }
      let t, real_opts = {};
      if (parsedUrl.protocol == "http:") {
        real_opts['createConnection'] = () => socket
        t = http;
      } else {
        real_opts['socket'] = socket;
        t = https;
      }
      const real_req = t.request(url, real_opts, (res) => {
        res.setEncoding('utf-8')
        let rawData = []
        res.on('data', (chunk) => rawData.push(chunk));
        res.on('end', () => resolve(rawData.join('')));
      });
      real_req.on('error', (e) => reject(e));
      real_req.end();
    }).end();
  });

  return res;
}

getWithProxy("https://httpbin.org/ip", {
  ip: '1.1.1.1',
  port: 5432,
  login: 'login',
  password: 'password'
}).then(
    (data) => console.log(data.trim()),
    (e) => console.log("Error: " + e.toString())
).then(
  () => getWithProxy("http://api.privateproxy.me:10738", {
    ip: '1.1.1.1',
    port: 5432,
    login: 'login',
    password: 'password'
  })
).then(
  (data) => console.log(data.trim()),
  (e) => console.log("Error: " + e.toString())
)
require 'net/http'

resp = Net::HTTP.start("api.privateproxy.me", 10738, "1.1.1.1", "5432", "login", "password") do |h|
  request = Net::HTTP::Get.new('/')
  h.request(request)
end

puts resp.body # "1.1.1.1\\n"
package main

import (
  "fmt"
  "io/ioutil"
  "net/http"
  "net/url"
  "time"
)

func main() {
  proxy, err := url.Parse("http://login:[email protected]:5432")
  if err != nil {
    return
  }
  proxyFunc := http.ProxyURL(proxy)
  tr := &http.Transport{
    MaxIdleConns:       10,
    IdleConnTimeout:    30 * time.Second,
    DisableCompression: true,
    Proxy:              proxyFunc,
  }
  client := &http.Client{
    Transport: tr,
  }
  resp, err := client.Get("http://api.privateproxy.me:10738")
  if err != nil {
    return
  }
  defer resp.Body.Close()
  bytes, err := ioutil.ReadAll(resp.Body)
  if err != nil {
    return
  }
  fmt.Print(string(bytes)) // "1.1.1.1\\n"
}
var handler = new HttpClientHandler();
handler.Proxy = new WebProxy("http://login:[email protected]:5432/");

using (var httpClient = new HttpClient(handler))
{
  using (var request = new HttpRequestMessage(new HttpMethod("GET"), "http://api.privateproxy.me:10738"))
  {
    var response = await httpClient.SendAsync(request);
    // response.Content - "1.1.1.1\\n"
  }
}

http://api.privateproxy.me:10738 - 以文本模式显示您当前的 IP 地址

使用反向连接代理与使用普通代理没有区别。Backconnect 代理服务器的作用与普通代理服务器相同,只是目标网站看到的 IP 地址不同,具体取决于交换间隔设置/手动交换。

如果您已将自己的 IP 地址添加到授权 IP 列表中,则无需指定证书。授权 IP 并不是强制性的,您可以继续使用证书授权,哪种方式更方便都可以。

如果您要编写自己的软件来访问某个网站,请添加 User-Agent 等标头,以便请求看起来像是来自浏览器。


浏览器使用建议

  • 关闭 WebRTC,因为即使使用代理服务器,它也会破坏你的真实 IP 地址,甚至你的本地内网 IP 地址。这里有一个针对不同浏览器的禁用指南链接: https://www.vpnunlimitedapp.com/blog/how-to-disable-webrtc-in-chrome-and-other-browsers
  • 使用 Chrome 浏览器的 ghostery 等禁用跟踪器插件,网站仍能通过浏览器指纹识别你的身份。
  • 如果可能,将本地计算机时间设置为代理服务器时区。
  • 如果使用 backconnect,最好将交换时间间隔设置为 5 分钟或更长,这样就不会经常出现 IP 变更。

Using Proxies with Python-Selenium

python-selenium + Firefox(geckodriver)

要在 firefox 中使用 selenium,你需要安装这些项目:

如果使用凭据认证,还需要

例如,使用代理凭据:

from seleniumwire import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

path_to_firefox_binary = '' # !!! set this variable !!!
path_to_geckodriver_binary = '' # !!! set this variable !!!

wire_options = {
  'proxy': {
    'http': 'http://login:[email protected]:5432',
    'https': 'http://login:[email protected]:5432',
    'no_proxy': 'localhost,127.0.0.1'
  }
}
binary = FirefoxBinary(path_to_firefox_binary)

options = Options()
options.headless = True
browser = webdriver.Firefox(
  options=options,
  firefox_binary=binary,
  executable_path=path_to_geckodriver_binary,
  seleniumwire_options=wire_options
)

browser.get("http://api.privateproxy.me:10738")
element = WebDriverWait(browser, 10).until(
  EC.visibility_of_element_located((By.CSS_SELECTOR, "pre"))
)
print(element.text)
browser.quit()

使用 IP 授权的示例:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

path_to_firefox_binary = '' # !!! set this variable !!!
path_to_geckodriver_binary = '' # !!! set this variable !!!
proxy_ip = '1.1.1.1'
proxy_port = 5432

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", proxy_ip)
profile.set_preference("network.proxy.http_port", proxy_port)
profile.set_preference("network.proxy.ssl", proxy_ip)
profile.set_preference("network.proxy.ssl_port", proxy_port)
profile.update_preferences()

binary = FirefoxBinary(path_to_firefox_binary)
options = Options()
options.headless = True
browser = webdriver.Firefox(
  options=options,
  firefox_binary=binary,
  executable_path=path_to_geckodriver_binary,
  firefox_profile=profile
)
browser.get("http://api.privateproxy.me:10738")
element = WebDriverWait(browser, 10).until(
  EC.visibility_of_element_located((By.CSS_SELECTOR, "pre"))
)
print(element.text)
browser.quit()

这两个示例都以无头模式启动 firefox,因此在执行这些示例时浏览器将保持隐藏状态。


python-selenium + Chrome(chromedriver)

要在 Chrome 浏览器中使用硒,你需要安装这些项目:

使用凭证授权的示例:

import os
import zipfile
import hashlib
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

proxy = "1.1.1.1:5432"
credentials = "login:password"
path_to_chrome_binary = '' !!! set this variable !!!
path_to_chromedriver_binary = '' !!! set this variable !!!

def generate_extension(proxy, credentials):
  ip, port = proxy.split(':')
  login, password = credentials.split(':')
  manifest_json = """
  {
      "version": "1.0.0",
      "manifest_version": 2,
      "name": "Chrome Proxy",
      "permissions": [
          "proxy",
          "tabs",
          "unlimitedStorage",
          "storage",
          "",
          "webRequest",
          "webRequestBlocking"
      ],
      "background": {
          "scripts": ["background.js"]
      },
      "minimum_chrome_version":"22.0.0"
  }
  """

  background_js = """
  var config = {
          mode: "fixed_servers",
          rules: {
          singleProxy: {
              scheme: "http",
              host: "%s",
              port: parseInt(%s)
          },
          bypassList: ["localhost"]
          }
      };

  chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

  function callbackFn(details) {
      return {
          authCredentials: {
              username: "%s",
              password: "%s"
          }
      };
  }

  chrome.webRequest.onAuthRequired.addListener(
              callbackFn,
              {urls: [""]},
              ['blocking']
  );
  """ % (ip, port, login, password)

  sha1 = hashlib.sha1()
  sha1.update(("%s:%s" % (proxy, credentials)).encode('utf-8'))
  filename = sha1.hexdigest() + ".zip"

  with zipfile.ZipFile(filename, 'w') as zp:
    zp.writestr("manifest.json", manifest_json)
    zp.writestr("background.js", background_js)

  return filename

extension_name = generate_extension(proxy, credentials)
options = Options()
options.binary_location = path_to_chrome_binary
options.add_extension(extension_name)
driver = webdriver.Chrome(
  executable_path = path_to_chromedriver_binary,
  options=options,
)
driver.get('http://api.privateproxy.me:10738/')
element = WebDriverWait(driver, 30).until(
  EC.visibility_of_element_located((By.CSS_SELECTOR, "pre"))
)
print(element.text)
driver.quit()
os.remove(extension_name)

遗憾的是,在使用凭证时存在一些限制:

  • 没有无头模式
  • 必须为每个代理 + 凭据集生成并存储扩展名。我们找不到更简单的方法。

使用 ip 授权的示例:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

path_to_chrome_binary = '' # !!! set this variable !!!
path_to_chromedriver_binary = '' # !!! set this variable !!!
proxy = "1.1.1.1:5432"

options = Options()
options.binary_location = path_to_chrome_binary
options.headless = True
options.add_argument("--proxy-server=%s" % proxy)

driver = webdriver.Chrome(
  executable_path = path_to_chromedriver_binary,
  options=options,
)
driver.get('http://api.privateproxy.me:10738/')
element = WebDriverWait(driver, 30).until(
  EC.visibility_of_element_located((By.CSS_SELECTOR, "pre"))
)
print(element.text)
driver.quit()

使用 Node.JS Puppeteer 代理

Puppeteer + Node.js + chrome 浏览器

目前,我们只有一个如何在 puppeteer 和 Chrome 浏览器中使用代理的示例。

为此,您需要在安装 puppeteer 时使用环境变量 PUPPETEER_PRODUCT=chrome:

PUPPETEER_PRODUCT=chrome npm install puppeteer

您还需要代理链软件包:

npm install proxy-chain

代码示例

const puppeteer = require('puppeteer');
const proxyChain = require('proxy-chain');

(async() => {
  const oldProxyUrl = 'http://login:[email protected]:5432';
  const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl);

  const browser = await puppeteer.launch({
    args: [`--proxy-server=${newProxyUrl}`],
  });

  const page = await browser.newPage();
  await page.goto('https://httpbin.org/ip');
  const element = await page.$('pre');
  const text = await page.evaluate(element => element.textContent, element);
  console.log(text);
  await browser.close();

  await proxyChain.closeAnonymizedProxy(newProxyUrl, true);
})();

最后更新于 2023 年 12 月 12 日

您推荐代理服务吗?

点击奖杯即可颁奖!

平均评分 0 /5.计票: 0

目前没有投票!成为第一个给本帖评分的人。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

zh_CNChinese
滚动到顶部