/**
* 請確保安裝了request和bluebird兩個模塊
* 安裝模塊:打開NODEJS-->輸入npm install request-->輸入npm install bluebird
**/
var request = require("request");
var Promise = require("bluebird");
// 請填寫無憂代理訂單號
var order = 'please-input-your-order-here';
// 要測試的網址
var targetURL = 'http://pv.sohu.com/cityjson?ie=utf-8';
// 請求超時時間
var timeout = 8000;
// 測試次數
var testTime = 5;
// 間隔多少毫秒調用一次接口
var sleepTime = 5000;
var apiURL = 'http://api.ip.data5u.com/dynamic/get.html?order=' + order + '&sep=3';
console.log('>>>> start test dynamic ip');
function getProxyList() {
return new Promise((resolve, reject) => {
var options = {
method: 'GET',
url: apiURL,
gzip: true,
encoding: null,
headers: {},
};
request(options, function (error, response, body) {
try {
if (error) throw error;
var ret = (body + '').match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}/g);
resolve(ret);
} catch (e) {
return reject(e);
}
});
});
}
function execute(){
getProxyList().then(function (proxyList) {
var targetOptions = {
method: 'GET',
url: targetURL,
timeout: timeout,
encoding: null,
};
proxyList.forEach(function (proxyurl) {
console.log(`* testing `);
var startTimestamp = (new Date()).valueOf();
targetOptions.proxy = 'http://' + proxyurl;
request(targetOptions, function (error, response, body) {
try {
if (error) throw error;
body = body.toString();
var endTimestamp = (new Date()).valueOf();
console.log(' > time ' + (endTimestamp - startTimestamp) + 'ms ' + body);
} catch (e) {
console.error(e);
}
});
});
}).catch(e => {
console.log(e);
})
}
// 定時執行
var interval = setInterval(function(){
if(testTime > 0){
execute()
} else {
clearInterval(interval);
console.log('<<<< end test dynamic ip');
}
testTime = testTime - 1;
}, sleepTime);
/**
* 先運行npm install moment安裝moment模塊,運行npm install crypto安裝crypto模塊
*/
var request = require("request");
var moment = require("moment");
var crypto = require('crypto');
var options = {};
var raw = "替換成你的IP提取碼:替換成你的動態轉發密碼";
options.method = "GET";
options.url = "https://www.so.com";
options.headers = {
"Proxy-Authorization": "Basic " + new Buffer(raw).toString('base64')
};
options.rejectUnauthorized=false;
options.proxy = 'http://tunnel.data5u.com:56789';
var startTimestamp = (new Date()).valueOf();
request(options, function (error, response, body) {
try {
if (error) throw error;
body = body.toString();
var endTimestamp = (new Date()).valueOf();
console.log(' > time ' + (endTimestamp - startTimestamp) + 'ms ' + body);
} catch (e) {
console.error(e);
}
});