简体   繁体   English

如何知道node.js中的网络掩码?

[英]How to know network mask in node.js?

I'm developing a tool for networking and I don't know how to get the network mask of the computer that executes the program. 我正在开发一种用于联网的工具,但我不知道如何获取执行该程序的计算机的网络掩码。 I know I can get the IP by OS library, but I don't know how I could know the mask, Can you help me? 我知道我可以通过OS库获取IP,但是我不知道如何知道掩码,您能帮我吗?

Thank you in advance! 先感谢您!

EDIT: I'm using 0.10.* version... I know there's in 0.11.11 version the option "netmask" on require('os').networkInterfaces(). 编辑:我正在使用0.10。*版本...我知道在0.11.11版本中,require('os')。networkInterfaces()上的选项“ netmask”。 But I have to use 0.10.* version. 但是我必须使用0.10。*版本。

You can always execute ifconfig from your node script, then parse the output and extract the netmask parameter for the network interface you're interested in. 您始终可以从节点脚本中执行ifconfig ,然后解析输出并提取您感兴趣的网络接口的netmask参数。

You could run ifconfig interface_name | grep 'inet ' 您可以运行ifconfig interface_name | grep 'inet ' ifconfig interface_name | grep 'inet ' , where interface_name would be the interface you're interested in. Parsing the output of the above should be pretty easy. ifconfig interface_name | grep 'inet ' ,其中interface_name是您感兴趣的接口。解析上面的输出应该很容易。 On OSX, look for the value after 'netmask', on Linux 'Mask:' 在OSX上,在Linux“掩码”上查找“ netmask”后的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM