位置
位置定位可以说是配置代理最关键的一环。用户经常需要访问特定位置的代理服务器以实现各种目的。IPRoyal在这方面提供了多种的可能性,能够让用户针对该地区、国家、州省或地市,甚至是该位置的特定互联网服务提供商(ISP)。我们将在随后的段落中更详细地探讨这些选项,重点是本节中IPRoyal提供的全面定位功能。
地区
_region-
是配置区域的关键。添加此值可告诉我们的路由器筛选出位于该区域的代理。
示例:
curl -v -x http://username123:password321_region-europe@geo.iproyal.com:12321 -L http://example.com
<?php
$username = 'username123';
$password = 'password321_region-europe';
$proxy = 'geo.iproyal.com:12321';
$url = 'http://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>
import requests
from requests.auth import HTTPProxyAuth
username = 'username123'
password = 'password321_region-europe'
proxy = 'geo.iproyal.com:12321'
url = 'http://example.com'
proxies = {
'http': f'http://{proxy}',
'https': f'http://{proxy}',
}
auth = HTTPProxyAuth(username, password)
response = requests.get(url, proxies=proxies, auth=auth)
print(response.text)
const http = require('http');
const username = 'username123';
const password = 'password321_region-europe';
const proxyHost = 'geo.iproyal.com';
const proxyPort = 12321;
const targetUrl = 'http://example.com';
const targetUrlObj = new URL(targetUrl);
const targetHost = targetUrlObj.host;
const targetPath = targetUrlObj.pathname;
const auth = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
const options = {
host: proxyHost,
port: proxyPort,
method: 'GET',
path: targetUrl,
headers: {
'Host': targetHost,
'Proxy-Authorization': auth
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(data);
});
});
req.on('error', (error) => {
console.error('Error:', error.message);
});
req.end();
国家
_country-
是配置国家的关键。取值为两个字母的国家代码 (ISO 3166-1 alpha-2 format)。
可以选择多个国家。使用此配置解析代理时,我们的路由器将随机选择您设置的国家/地区,作为国家/地区密钥值之一。
示例:
curl -v -x http://username123:password321_country-dk,it,ie@geo.iproyal.com:12321 -L http://example.com
<?php
$username = 'username123';
$password = 'password321_country-dk,it,ie';
$proxy = 'geo.iproyal.com:12321';
$url = 'http://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>
import requests
from requests.auth import HTTPProxyAuth
username = 'username123'
password = 'password321_country-dk,it,ie'
proxy = 'geo.iproyal.com:12321'
url = 'http://example.com'
proxies = {
'http': f'http://{proxy}',
'https': f'http://{proxy}',
}
auth = HTTPProxyAuth(username, password)
response = requests.get(url, proxies=proxies, auth=auth)
print(response.text)
const http = require('http');
const username = 'username123';
const password = 'password321_country-dk,it,ie';
const proxyHost = 'geo.iproyal.com';
const proxyPort = 12321;
const targetUrl = 'http://example.com';
const targetUrlObj = new URL(targetUrl);
const targetHost = targetUrlObj.host;
const targetPath = targetUrlObj.pathname;
const auth = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
const options = {
host: proxyHost,
port: proxyPort,
method: 'GET',
path: targetUrl,
headers: {
'Host': targetHost,
'Proxy-Authorization': auth
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(data);
});
});
req.on('error', (error) => {
console.error('Error:', error.message);
});
req.end();
城市
_city-
是锁定城市的关键。该值应该是城市的名称。
此外,在针对特定城市时,必须指定国家,因为多个国家可能有同名的城市。
示例:
curl -v -x http://username123:password321_country-de_city-berlin@geo.iproyal.com:12321 -L http://example.com
<?php
$username = 'username123';
$password = 'password321_country-us_state-iowa';
$proxy = 'geo.iproyal.com:12321';
$url = 'http://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>
import requests
from requests.auth import HTTPProxyAuth
username = 'username123'
password = 'password321_country-de_city-berlin'
proxy = 'geo.iproyal.com:12321'
url = 'http://example.com'
proxies = {
'http': f'http://{proxy}',
'https': f'http://{proxy}',
}
auth = HTTPProxyAuth(username, password)
response = requests.get(url, proxies=proxies, auth=auth)
print(response.text)
const http = require('http');
const username = 'username123';
const password = 'password321_country-de_city-berlin';
const proxyHost = 'geo.iproyal.com';
const proxyPort = 12321;
const targetUrl = 'http://example.com';
const targetUrlObj = new URL(targetUrl);
const targetHost = targetUrlObj.host;
const targetPath = targetUrlObj.pathname;
const auth = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
const options = {
host: proxyHost,
port: proxyPort,
method: 'GET',
path: targetUrl,
headers: {
'Host': targetHost,
'Proxy-Authorization': auth
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(data);
});
});
req.on('error', (error) => {
console.error('Error:', error.message);
});
req.end();
州
_state-
用于针对美国的一个州。该值应该是该州的名称。
一定要选择美国作为国家。
示例:
curl -v -x http://username123:password321_country-us_state-iowa@geo.iproyal.com:12321 -L http://example.com
<?php
$username = 'username123';
$password = 'password321_country-us_state-iowa';
$proxy = 'geo.iproyal.com:12321';
$url = 'http://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>
import requests
from requests.auth import HTTPProxyAuth
username = 'username123'
password = 'password321_country-us_state-iowa'
proxy = 'geo.iproyal.com:12321'
url = 'http://example.com'
proxies = {
'http': f'http://{proxy}',
'https': f'http://{proxy}',
}
auth = HTTPProxyAuth(username, password)
response = requests.get(url, proxies=proxies, auth=auth)
print(response.text)
const http = require('http');
const username = 'username123';
const password = 'password321_country-us_state-iowa';
const proxyHost = 'geo.iproyal.com';
const proxyPort = 12321;
const targetUrl = 'http://example.com';
const targetUrlObj = new URL(targetUrl);
const targetHost = targetUrlObj.host;
const targetPath = targetUrlObj.pathname;
const auth = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
const options = {
host: proxyHost,
port: proxyPort,
method: 'GET',
path: targetUrl,
headers: {
'Host': targetHost,
'Proxy-Authorization': auth
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(data);
});
});
req.on('error', (error) => {
console.error('Error:', error.message);
});
req.end();
互联网服务提供商(ISP)
_isp-
用于针对某个位置的特定互联网服务提供商(ISP)。该值应该是一个连接的提供商名称。
请确保将其链接到一个城市。某个单一的ISP通常存在于很多城市甚至国家。
示例:
curl -v -x http://username123:password321_country-gb_city-birmingham_isp-skyuklimited@geo.iproyal.com:12321 -L http://example.com
<?php
$username = 'username123';
$password = 'password321_country-gb_city-birmingham_isp-skyuklimited';
$proxy = 'geo.iproyal.com:12321';
$url = 'http://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $response;
}
curl_close($ch);
?>
import requests
from requests.auth import HTTPProxyAuth
username = 'username123'
password = 'password321_country-gb_city-birmingham_isp-skyuklimited'
proxy = 'geo.iproyal.com:12321'
url = 'http://example.com'
proxies = {
'http': f'http://{proxy}',
'https': f'http://{proxy}',
}
auth = HTTPProxyAuth(username, password)
response = requests.get(url, proxies=proxies, auth=auth)
print(response.text)
const http = require('http');
const username = 'username123';
const password = 'password321_country-gb_city-birmingham_isp-skyuklimited';
const proxyHost = 'geo.iproyal.com';
const proxyPort = 12321;
const targetUrl = 'http://example.com';
const targetUrlObj = new URL(targetUrl);
const targetHost = targetUrlObj.host;
const targetPath = targetUrlObj.pathname;
const auth = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
const options = {
host: proxyHost,
port: proxyPort,
method: 'GET',
path: targetUrl,
headers: {
'Host': targetHost,
'Proxy-Authorization': auth
}
};
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(data);
});
});
req.on('error', (error) => {
console.error('Error:', error.message);
});
req.end();
Last updated