os.networkInterfaces()
返回包含已分配网络地址的网络接口的对象。
¥Returns an object containing network interfaces that have been assigned a network address.
返回对象上的每个键都标识一个网络接口。关联的值是每个对象描述一个分配的网络地址的对象数组。
¥Each key on the returned object identifies a network interface. The associated value is an array of objects that each describe an assigned network address.
分配的网络地址对象上可用的属性包括:
¥The properties available on the assigned network address object include:
-
address<string> 分配的 IPv4 或 IPv6 地址¥
address<string> The assigned IPv4 or IPv6 address -
netmask<string> IPv4 或 IPv6 网络掩码¥
netmask<string> The IPv4 or IPv6 network mask -
family<string>IPv4或IPv6¥
family<string> EitherIPv4orIPv6 -
mac<string> 网络接口的 MAC 地址¥
mac<string> The MAC address of the network interface -
internal<boolean>true如果网络接口是环回接口或不可远程访问的类似接口;否则false¥
internal<boolean>trueif the network interface is a loopback or similar interface that is not remotely accessible; otherwisefalse -
scopeid<number> 数字的 IPv6 范围 ID(仅在family为IPv6时指定)¥
scopeid<number> The numeric IPv6 scope ID (only specified whenfamilyisIPv6) -
cidr<string> 使用 CIDR 表示法的路由前缀分配的 IPv4 或 IPv6 地址。如果netmask无效,则此属性设置为null。¥
cidr<string> The assigned IPv4 or IPv6 address with the routing prefix in CIDR notation. If thenetmaskis invalid, this property is set tonull.
{
lo: [
{
address: '127.0.0.1',
netmask: '255.0.0.0',
family: 'IPv4',
mac: '00:00:00:00:00:00',
internal: true,
cidr: '127.0.0.1/8'
},
{
address: '::1',
netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
family: 'IPv6',
mac: '00:00:00:00:00:00',
scopeid: 0,
internal: true,
cidr: '::1/128'
}
],
eth0: [
{
address: '192.168.1.108',
netmask: '255.255.255.0',
family: 'IPv4',
mac: '01:02:03:0a:0b:0c',
internal: false,
cidr: '192.168.1.108/24'
},
{
address: 'fe80::a00:27ff:fe4e:66a1',
netmask: 'ffff:ffff:ffff:ffff::',
family: 'IPv6',
mac: '01:02:03:0a:0b:0c',
scopeid: 1,
internal: false,
cidr: 'fe80::a00:27ff:fe4e:66a1/64'
}
]
}