闲来无聊撸了个域名 于是 TIZI.HOST诞生了
tizi.host使用项目racaljk-hosts的hosts
使用node脚本每半小时自动更新一次
var request = require('request');
var fs = require("fs");
var options = {
url: 'https://api.github.com/repos/racaljk/hosts',
headers: {
'User-Agent': 'request'
}
};
setInterval(xxx,1000*60*10)
function xxx(){
var now=new Date();
console.log(1900+now.getYear()+"-"+(now.getMonth()+1)+"-"+now.getDate()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()+'----');
function gettime(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
var time= Date.parse(info.pushed_at);
var webtime=new Date(time+480000).toLocaleString();
console.log('uptime:'+webtime);
fs.readFile('hosttime.txt', function (err, data) {
if (err) {
return console.error(err);
}
var localtime=data.toString();
console.log("localtime:" +localtime);
if (localtime==webtime) {console.log('no changer')}
else{
console.log('writeFile....')
fs.writeFile("hosttime.txt",webtime,function (err) {
if (err) throw err ;
console.log("TimeFile Saved !");
writehost();
});
}
});
}
}
function writehost(){
var hsotsoptions = {
url: 'https://raw.githubusercontent.com/racaljk/hosts/master/hosts',
headers: {
'User-Agent': 'request'
}
};
function gethosts(error, response, body) {
if (!error && response.statusCode == 200) {
var hosts=body;
fs.writeFile("hosts",hosts,function (err) {
if (err) throw err ;
console.log("hosts Saved !");
});
}
}
request(hsotsoptions, gethosts);
}
request(options, gettime);
}
通过githubapi获取时间与本地hosttime.txt文件进行比较 相同则舍弃 不相同则修改hosts
win客户端使用c#编写 源码