此博客为9925.org的镜像,登录9925.org可以查看到最新博文。

原文出处:http://ily.so/AV3yQv

在《使用EJS脚本实现花生壳动态域名更新服务(一)》中,我们粗暴的把代码放在一起,然后执行。利用EJS支持的“#include”预编译指令我们可以以更加优美的方式组织代码。

步骤如下:

把BASE64编码部分的代码复制到一个新建的脚本。

/**
* 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(''));}
};

将脚本命名为“base64.ejs”,放在一个你喜欢的目录,在例子中我们把这个文件保存在桌面。

路径如下:X:\Users\USER\Desktop\base64.ejs

再新建一个脚本,键入下面代码:

#include base64.ejsclear()
/*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);

将脚本命名为“花生壳更新.ejs”,放在与“base64.ejs”相同的目录内。

路径如下:X:\Users\USER\Desktop\花生壳更新.ejs

执行脚本“花生壳更新.ejs”后可更新花生壳域名。

注意:直接执行 base64.ejs 的脚本是没有结果的,这个脚本内只是定义了Base64编码的对象,并未调用。

在“花生壳更新.ejs”脚本的第一行我们会看到:

#include base64.ejs

这句代码的作用就是将“base64.ejs”内的代码copy到“花生壳更新.ejs”内的“#include base64.ejs”处,这个过程是通过EJS的预编译器实现的。

EJS脚本的执行过程如下:

需要注意的是“#include base64.ejs”的路径搜索问题,这里的搜索路径是当前运行的EJS脚本路径。

比如:X:\Users\USER\Desktop\花生壳更新.ejs,那么“#include base64.ejs”内的“base64.ejs”搜索目录就是“X:\Users\USER\Desktop\”。

更多关于“#include”指令的信息请参考《在EJS脚本内使用“#include”预编译指令》。

转载于:https://www.cnblogs.com/easton/p/4306336.html

使用EJS脚本实现花生壳动态域名更新服务(二)相关推荐

  1. 使用EJS脚本实现花生壳动态域名更新服务(一)

    此博客为9925.org的镜像,登录9925.org可以查看到最新博文. 原文出处:http://ily.so/FrQBne 花生壳提供了动态域名服务,动态域名可实现几乎实时生效的DNS解析服务,并且 ...

  2. 花生壳动态域名详细试用方法

    花生壳动态域名使用方法(详解) 1. 首先登录 花生壳网站  http://www.oray.com/,在 导航栏 中选择"花生壳",然后点击"花生壳下载",根 ...

  3. liunx动态获取ip解决花生壳动态域名失效问题

    现象描述: 1. 我们有些客户是在公司内网,但是也想在外网访问,所以这个时间就想到使用花生壳来实现,搭建nginx来进行反向代理到花生壳域名. 2.搭建完花生壳动态域名解析服务和nginx反向代理服务 ...

  4. 教程:动手用自己电脑搭建一个网站 (nat123 花生壳 动态域名 个人电脑做服务器)...

    先ps一下..今晚试了N种方法,终于找到一个靠谱 免费 好用的方法,来改装自己电脑成为服务器,在外网也能通过域名访问了!!! 需要准备的东西: Tomcat:这个是web容器,其实有了这个就已经让电脑 ...

  5. 百度SEO花生壳动态域名解析软件 v5.3.0.34889

    简介: 花生壳是一套有效免费的动态域名解析服务客户端软件.当您安装并注册该项服务,可实现在家或者异地搭建网站.FTP.Mail. 异地或分支机构访问办公OA.CRM.ERP系统."花生壳&q ...

  6. Ubnt EdgeMax 路由器使用花生壳的ddns更新方法

    使用SSH 登录 Ubnt,然后执行如下指令,将对应的参数修改成你自己的即可. configure set service dns dynamic interface pppoe1 service c ...

  7. Debian下安装3322动态域名更新程序

    Ez-ipupdate 是一个动态域名更新程序,可以更新希网的动态域名. 1.对于动态域名(DYNDNS),service-type参数应该选择 qdns 2.对于静态域名(STATDNS),serv ...

  8. DNS云学堂 | 替代传统Windows DNS功能,不得不说的动态域名更新

    为满足应用的双活改造和灵活切换的场景,很多企业依靠DNS系统实现应用与IP的解耦.搭建专业的DNS系统,替代传统Windows的DNS功能,成为了企业信息化发展健全的一个必要过程. 与域控结合,组建更 ...

  9. Mikrotik RouterOS-脚本-花生壳动态域名解析

    花生壳官方提供给用户的"如何在ROS中设置花生壳ddns(公网版)"错漏百出,根本无法使用. 为了解决此问题还特意学习了"Mikrotik RouterOS的脚本语法&q ...

最新文章

  1. Python异步通信模块asyncore
  2. sybase备份问题
  3. 解决 minicom 不能接收键盘输入问题
  4. Struts2的两个蝴蝶飞,你好简单开发(一)
  5. Game of Swapping Numbers
  6. 自编码 Autoencoder
  7. console中应用MFC类的方法
  8. android js桥接,一种JavaScript和原生APP之间数据交互方法与流程
  9. C语言中strstr函数
  10. CUDA Occupancy Calculator中计算占用率
  11. VBA 合并同文件夹下多工作簿中同名工作表到 一工作簿一工作表
  12. linkedin python 领英技能 测评
  13. vsftp登录失败_VSFTP虚拟账户无法登陆530 Login incorrect错误解决方法 | 系统之家官网...
  14. [ROS] KDL + DH 参数 + 正解
  15. Win系统 - 你知道 insert 键的隐藏功能吗?
  16. 7-4 房产税费计算2022.6.24
  17. 【Java+MySQL】随机添加测试数据栗子
  18. 第7章第22节:双图排版:两张图片并列靠边对齐 [PowerPoint精美幻灯片实战教程]
  19. IMPERVA-WAF 设备替换方案
  20. 【网络】交换机 VLAN 网关 路由器

热门文章

  1. 有序的HashMap:LinkedHashMap
  2. python进行 t 检验
  3. Spring Boot基础入门+内置tomcat+自动配置浅谈分析
  4. 仓央嘉措 ❤《见与不见》的全文 ❤
  5. 数据可视化分析教学课件——FineBI实验册节选====库存分析
  6. 未来人工智能自主学习网络的构建
  7. ImageGear for .NET扫描打印等图形图像处理控件介绍使用手册
  8. CSR8675学习笔记:从外部Flash读取bin文件
  9. android画直角坐标系,用Android画个五角星
  10. Apache ab压力测试说明