Linux 下 NodeJS 获取 IP 等信息

xiaoxiao2021-02-28  158

demo 如下;

/* *Linux 环境下获取网络接口信息 */ //导入os模块 var os = require("os"); //获取系统的网络接口信息 var netInfo = os.networkInterfaces(); //ip地址 var ip = netInfo.eth0[0].address; //子网掩码 var netMask = netInfo.eth0[0].netmask; //协议族 var family = netInfo.eth0[0].family; //Mac地址 var macAddr = netInfo.eth0[0].mac; //验证 console.log("IP:"+ip); console.log("NetMask:"+netMask); console.log("Family:"+family); console.log("Mac:"++macAddr);

转载请注明原文地址: https://www.6miu.com/read-22193.html

最新回复(0)