使用EJS脚本实现花生壳动态域名更新服务(一)
此博客为9925.org的镜像,登录9925.org可以查看到最新博文。
原文出处:http://ily.so/FrQBne
花生壳提供了动态域名服务,动态域名可实现几乎实时生效的DNS解析服务,并且花生壳还提供了webapi更新域名解析的服务。
通过EJS我们可以轻松调用花生壳提供的webapi服务实现动态域名更新功能。
注意:这个webapi是采用Http Basic Authentication(HTTP基本认证)的,因此账号和密码必须用BASE64(account:password)编码后放在请求头。具体实现请参考下面代码,Base64编码部分代码copy自互联网,版权由原作者所有。
代码如下:
clear() /** * UTF16和UTF8转换对照表 * U+00000000 – U+0000007F 0xxxxxxx * U+00000080 – U+000007FF 110xxxxx 10xxxxxx * U+00000800 – U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx * U+00010000 – U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx * U+00200000 – U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx * U+04000000 – U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ var Base64 = {// 转码表 table : ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K', 'L', 'M', 'N', 'O' ,'P','Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X','Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f','g', 'h', 'i', 'j', 'k', 'l', 'm', 'n','o', 'p', 'q', 'r', 's', 't', 'u', 'v','w', 'x', 'y', 'z', '0', '1', '2', '3','4', '5', '6', '7', '8', '9', '+', '/'],UTF16ToUTF8 : function(str) {var res = [], len = str.length;for (var i = 0; i < len; i++) {var code = str.charCodeAt(i);if (code > 0x0000 && code <= 0x007F) {// 单字节,这里并不考虑0x0000,因为它是空字节// U+00000000 – U+0000007F 0xxxxxxx res.push(str.charAt(i));} else if (code >= 0x0080 && code <= 0x07FF) {// 双字节// U+00000080 – U+000007FF 110xxxxx 10xxxxxx// 110xxxxxvar byte1 = 0xC0 | ((code >> 6) & 0x1F);// 10xxxxxxvar byte2 = 0x80 | (code & 0x3F);res.push(String.fromCharCode(byte1), String.fromCharCode(byte2));} else if (code >= 0x0800 && code <= 0xFFFF) {// 三字节// U+00000800 – U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx// 1110xxxxvar byte1 = 0xE0 | ((code >> 12) & 0x0F);// 10xxxxxxvar byte2 = 0x80 | ((code >> 6) & 0x3F);// 10xxxxxxvar byte3 = 0x80 | (code & 0x3F);res.push(String.fromCharCode(byte1), String.fromCharCode(byte2), String.fromCharCode(byte3));} else if (code >= 0x00010000 && code <= 0x001FFFFF) {// 四字节// U+00010000 – U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx} else if (code >= 0x00200000 && code <= 0x03FFFFFF) {// 五字节// U+00200000 – U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx} else /** if (code >= 0x04000000 && code <= 0x7FFFFFFF)*/ {// 六字节// U+04000000 – U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx }}return res.join('');},UTF8ToUTF16 : function(str) {var res = [], len = str.length;var i = 0;for (var i = 0; i < len; i++) {var code = str.charCodeAt(i);// 对第一个字节进行判断if (((code >> 7) & 0xFF) == 0x0) {// 单字节// 0xxxxxxx res.push(str.charAt(i));} else if (((code >> 5) & 0xFF) == 0x6) {// 双字节// 110xxxxx 10xxxxxxvar code2 = str.charCodeAt(++i);var byte1 = (code & 0x1F) << 6;var byte2 = code2 & 0x3F;var utf16 = byte1 | byte2;res.push(Sting.fromCharCode(utf16));} else if (((code >> 4) & 0xFF) == 0xE) {// 三字节// 1110xxxx 10xxxxxx 10xxxxxxvar code2 = str.charCodeAt(++i);var code3 = str.charCodeAt(++i);var byte1 = (code << 4) | ((code2 >> 2) & 0x0F);var byte2 = ((code2 & 0x03) << 6) | (code3 & 0x3F);var utf16 = ((byte1 & 0x00FF) << 8) | byte2res.push(String.fromCharCode(utf16));} else if (((code >> 3) & 0xFF) == 0x1E) {// 四字节// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx} else if (((code >> 2) & 0xFF) == 0x3E) {// 五字节// 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx} else /** if (((code >> 1) & 0xFF) == 0x7E)*/ {// 六字节// 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx }}return res.join('');},encode : function(str) {if (!str) {return '';}var utf8 = this.UTF16ToUTF8(str); // 转成UTF8var i = 0; // 遍历索引var len = utf8.length;var res = [];while (i < len) {var c1 = utf8.charCodeAt(i++) & 0xFF;res.push(this.table[c1 >> 2]);// 需要补2个=if (i == len) {res.push(this.table[(c1 & 0x3) << 4]);res.push('==');break;}var c2 = utf8.charCodeAt(i++);// 需要补1个=if (i == len) {res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);res.push(this.table[(c2 & 0x0F) << 2]);res.push('=');break;}var c3 = utf8.charCodeAt(i++);res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);res.push(this.table[((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6)]);res.push(this.table[c3 & 0x3F]);}return res.join('');},decode : function(str) {if (!str) {return '';}var len = str.length;var i = 0;var res = [];while (i < len) {code1 = this.table.indexOf(str.charAt(i++));code2 = this.table.indexOf(str.charAt(i++));code3 = this.table.indexOf(str.charAt(i++));code4 = this.table.indexOf(str.charAt(i++));c1 = (code1 << 2) | (code2 >> 4);c2 = ((code2 & 0xF) << 4) | (code3 >> 2);c3 = ((code3 & 0x3) << 6) | code4;res.push(String.fromCharCode(c1));if (code3 != 64) {res.push(String.fromCharCode(c2));}if (code4 != 64) {res.push(String.fromCharCode(c3));}}return this.UTF8ToUTF16(res.join(''));} }; /*good 更新成功,域名的IP地址已经更新,同时会返回本次更新成功的IP,用空格隔开,如:good 1.2.3.4nochg 更新成功,但没有改变IP。一般这种情况为本次提交的IP跟上一次的一样notfqdn 未有激活花生壳的域名nohost 域名不存在或未激活花生壳nochg 更新成功,但没有改变IP。一般这种情况为本次提交的IP跟上一次的一样abuse 请求失败,频繁请求或验证失败时会出现!donator 表示此功能需要付费用户才能使用,如https911 系统错误 */ var hostname = prompt("请输入要更新的动态域名:"); var user = prompt("请输入账号:"); var pwd = prompt("请输入密码:"); var result = http.get("http://ddns.oray.com/ph/update?hostname=" + hostname, "User-Agent:Oray\nAuthorization:Basic " + Base64.encode(user + ":" + pwd), "utf-8"); console.log(result);
将代码复制到R5以上版本的IDE工具可运行。
转载于:https://www.cnblogs.com/easton/p/4306329.html
使用EJS脚本实现花生壳动态域名更新服务(一)相关推荐
- 使用EJS脚本实现花生壳动态域名更新服务(二)
此博客为9925.org的镜像,登录9925.org可以查看到最新博文. 原文出处:http://ily.so/AV3yQv 在<使用EJS脚本实现花生壳动态域名更新服务(一)>中,我们粗 ...
- 花生壳动态域名详细试用方法
花生壳动态域名使用方法(详解) 1. 首先登录 花生壳网站 http://www.oray.com/,在 导航栏 中选择"花生壳",然后点击"花生壳下载",根 ...
- liunx动态获取ip解决花生壳动态域名失效问题
现象描述: 1. 我们有些客户是在公司内网,但是也想在外网访问,所以这个时间就想到使用花生壳来实现,搭建nginx来进行反向代理到花生壳域名. 2.搭建完花生壳动态域名解析服务和nginx反向代理服务 ...
- 教程:动手用自己电脑搭建一个网站 (nat123 花生壳 动态域名 个人电脑做服务器)...
先ps一下..今晚试了N种方法,终于找到一个靠谱 免费 好用的方法,来改装自己电脑成为服务器,在外网也能通过域名访问了!!! 需要准备的东西: Tomcat:这个是web容器,其实有了这个就已经让电脑 ...
- 百度SEO花生壳动态域名解析软件 v5.3.0.34889
简介: 花生壳是一套有效免费的动态域名解析服务客户端软件.当您安装并注册该项服务,可实现在家或者异地搭建网站.FTP.Mail. 异地或分支机构访问办公OA.CRM.ERP系统."花生壳&q ...
- Ubnt EdgeMax 路由器使用花生壳的ddns更新方法
使用SSH 登录 Ubnt,然后执行如下指令,将对应的参数修改成你自己的即可. configure set service dns dynamic interface pppoe1 service c ...
- Debian下安装3322动态域名更新程序
Ez-ipupdate 是一个动态域名更新程序,可以更新希网的动态域名. 1.对于动态域名(DYNDNS),service-type参数应该选择 qdns 2.对于静态域名(STATDNS),serv ...
- DNS云学堂 | 替代传统Windows DNS功能,不得不说的动态域名更新
为满足应用的双活改造和灵活切换的场景,很多企业依靠DNS系统实现应用与IP的解耦.搭建专业的DNS系统,替代传统Windows的DNS功能,成为了企业信息化发展健全的一个必要过程. 与域控结合,组建更 ...
- Mikrotik RouterOS-脚本-花生壳动态域名解析
花生壳官方提供给用户的"如何在ROS中设置花生壳ddns(公网版)"错漏百出,根本无法使用. 为了解决此问题还特意学习了"Mikrotik RouterOS的脚本语法&q ...
最新文章
- ACMNO.25 C语言-间隔输出 写一函数,输入一个四位数字,要求输出这四个数字字符,但每两个数字间空格。如输入1990,应输出1 9 9 0。 输入 一个四位数 输出 增加空格输出
- VINS-Mono(经典论文阅读)
- 下拉列表select显示ng-options
- Boost:ssl服务测试程序
- c++primer 5th第15章基础、课后习题自己解析、心得体会等
- Node.js 常用Mongoose方法
- 运动会成绩管理系统python_Python 实现简易版成绩管理系统
- 关于router name 的url重写 --frontname rewrite frontname重写!
- thinkphp 多字段排序
- 函数 注释规范_Go语言编码规范
- Q4_一个事物领导另一个
- 深度学习自动调参工具,NNI使用
- Linux中的sh+source+export
- 可执行jar包的maven配置
- Android 第三方SDK特征的收集
- 跨年烟花 html 代码汇总
- 适合中小企业的项目管理系统有哪些?
- VB如何自动保存_VB编写的身份证号自动识别实用程序
- 基于JSP的婚恋交友网
- Git创建新分支并提交到github