Skip to content

Instantly share code, notes, and snippets.

@g8up
Created September 20, 2016 06:12
Show Gist options
  • Save g8up/76410f0e770e1bc82700f7885f767c8b to your computer and use it in GitHub Desktop.
Save g8up/76410f0e770e1bc82700f7885f767c8b to your computer and use it in GitHub Desktop.
[Node.js]向 XX-net 中导入备份的 IP
#!/usr/bin/env node
/**
* 自动向 XX-net 中导入备份的 IP
* 环境:nodejs, `npm install node-fetch -g`
* 安装:将此文件放置到 files 所在目录,命名为 import-ip.js
* 执行:node import-ip.js
*/
var fs = require('fs');
var fetch = require('node-fetch');
var url = 'http://127.0.0.1:8085/module/gae_proxy/control/importip?cmd=importip';
function submit ( data ){
var options = {
method: 'POST',
body: "ipList=" + data,
headers:{
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
};
fetch( url, options)
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});
}
/**
* files 中存储格式:一行一个 IP
*/
var files = [
"2016-8-23.txt",
"2016-8-24.txt",
"2016-9-6.txt"
];
files.forEach( function( file ){
var data = (function(){
var ipStr = fs.readFileSync(file, 'utf-8');
var ips = ipStr.split('\r\n');
console.log('IP count:', ips.length);
return ips.join('|');
})();
submit( data );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment