title: ddns刷新脚本
date: 2017-07-10 09:53:06
tags: raspberry,树莓派,nodejs,ddns
ddns刷新脚本
继发布树莓派保持网络连接shell脚本之后,很快就使用了花生壳来添加ddns.但是当时偷懒使用的是傻瓜式的频繁刷新,最近闲来无事开始修改脚本。水平有限没有使用shell脚本,使用的是node.js的脚本
node.js脚本
var http = require('http');
var dns = require('dns');
var fs = require('fs');
var currentIp = "";
dns.lookup('域名', function(err, address, family){
if(err) throw err;
currentIp = address;
checkIP();
});
function checkIP(){
var options = {
hostname:'ddns.oray.com',
port:80,
path:'/checkip',
method:'GET',
}
var req = http.request(options, function (res){
res.setEncoding('utf8');
res.on('data',function(chunk){
var location = chunk.indexOf('Current IP Address: ');
if (location>=0) {
var lastLocation = chunk.indexOf('