1.punycodepunycode模块转换为punycode编码punycode模块内部使用punycode.js类库将域名从本地语言使用的各种编码转换为可用于DNS服务器的punycode编码,因为核心操作系统是英文的,DNS服务器的解析也是用英文代码交换的,所以DNS服务器不支持直接用本地语言进行域名解析。所有本地语言的域名解析都需要转换成punycode编码,然后由DNS服务器解析punycode编码。encode(string),将Unicode编码的字符串转换为punycode编码的字符串decode(string),将punycode编码的字符串转换为Unicode编码的字符串toASCII(domain),用于将Unicode编码格式的域名转换为punycode编码格式域名,该方法只能转换本地语言域名,不能将英文域名转换为Unicode(domain),用于将punycode编码的域名转换为Unicode编码的域名,该方法只能转换本地语言域名,不转换英文域名ucs2.encode(codePoints),用于将UCS-2编码数组转换为字符串ucs2.decode(string),用于将字符串转换为UCS-2编码数组punycode.version,显示punycode.js类库版本号constpunycode=require('punycode');console.log(punycode.encode('Hello'));//6qq79vconsole.log(punycode.decode('6qq79v'));//你好console.log(punycode.toASCII('www.hello.com'));//www.xn--6qq79v.comconsole.log(punycode.toUnicode('www.xn--6qq79v.com'));//www.hello.comconsole.log(punycode.ucs2.encode([97,98,99]));//abcconsole.log(punycode.ucs2.encode([0x1D306]));//\uD834\uDF06console.log(punycode.ucs2.decode('abc'));//[97,98,99]console.log(punycode.ucs2.decode('\uD834\uDF06'));//[119558]2.os模块使用os模块获取操作系统信息os.tmpdir(),获取操作系统中存放临时文件的默认目录os.endianness(),获取CPU的字节序,返回值可能是BE和LEos.hostname(),获取计算机名os.type(),获取操作系统类型os.platform(),获取操作系统平台os.arch(),获取CPUarchitectureos.release(),获取操作系统版本号os。uptime(),获取系统当前运行时间,以秒为单位systemAmount,单位是byteos.freemem(),返回系统空闲内存的数量os.cpus()返回一个数组,存放了CPU核心的各种信息,包括CPU规格,运行速度(以MHz为单位))并运行时间信息os.networkInterfaces(),返回一个数组,存储系统中所有的网络接口os.EOL,定义一个EOL常量,常量值为操作系统中使用的换行符\r\nconstos=要求('os');console.log(os.tmpdir());///tmpconsole.log(os.endianness());//LEconsole.log(os.hostname());//Homerconsole.log(os.type());//Linuxconsole.log(os.platform());//linuxconsole.log(os.arch());//x64console.log(os.release());//3.10.0-693.17.1.el7.x86_64console.log(os.uptime());//108console.log(os.loadavg());//[2.48583984375,1.01318359375,0.3740234375]console.log(os.totalmem());//1910771712console.log(os.freemem());//76935168console.log(os.cpus());/***[{model:'Intel(R)Core(TM)i5-4210UCPU@1.70GHz',*speed:2401,*times:{user:194900,nice:21800,sys:210000,idle:477900,irq:0}},*{model:'Intel(R)Core(TM)i5-4210UCPU@1.70GHz',*speed:2401,*times:{user:157300,nice:19400,sys:205400,idle:543800,irq:0}},*{model:'Intel(R)Core(TM)i5-4210UCPU@1.70GHz',*speed:2401,*times:{user:149700,nice:4200,sys:212600,idle:548500,irq:0}},*{model:'Intel(R)Core(TM)i5-4210UCPU@1.70GHz',*速度:2401,*times:{user:156200,nice:2600,sys:213100,idle:501300,irq:0}}]***/console.log(os.networkInterfaces());/***{lo:*[{地址:'127.0.0.1',*网络掩码:'255.0.0.0',*family:'IPv4',*mac:'00:00:00:00:00:00',*internal:true},*{address:'::1',*netmask:'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',*family:'IPv6',*mac:'00:00:00:00:00:00',*scopeid:0,*internal:true}],*ens33:*[{地址:'192.168.71.147',*网络掩码:'255.255.255.0',*系列:'IPv4',*mac:'00:0c:29:e3:04:c1',*内部:false},*{地址:'fe80::20c:29ff:fee3:4c1',*网络掩码:'ffff:ffff:ffff:ffff::',*系列:'IPv6',*mac:'00:0c:29:e3:04:c1',*scopeid:2,*internal:false}]}***/console.log(os.EOL);//\r\n
