networkInterfaces() added DHCP status mac OS

This commit is contained in:
Sebastian Hildebrandt 2020-01-06 22:34:53 +01:00
parent 4dccb59326
commit b0308d4efb

View File

@ -486,7 +486,7 @@ function getLinuxIfaceConnectionName(interfaceName) {
} }
} }
function getLinuxDHCPnNics() { function getLinuxDHCPNics() {
// alternate methods getting interfaces using DHCP // alternate methods getting interfaces using DHCP
let cmd = 'ip a'; let cmd = 'ip a';
let result = []; let result = [];
@ -563,6 +563,20 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
} }
} }
function getDarwinIfaceDHCPstatus(iface) {
let result = false;
const cmd = `ipconfig getpacket "${iface}" 2>/dev/null \| grep lease_time;`;
try {
const lines = execSync(cmd).toString().split('\n');
if (lines.length && lines[0].startsWith('lease_time')) {
result = true;
}
} catch (e) {
util.noop();
}
return result;
}
function getLinuxIfaceDNSsuffix(connectionName) { function getLinuxIfaceDNSsuffix(connectionName) {
if (connectionName) { if (connectionName) {
const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep ipv4.dns-search;`; const cmd = `nmcli connection show "${connectionName}" 2>/dev/null \| grep ipv4.dns-search;`;
@ -651,7 +665,7 @@ function networkInterfaces(callback) {
duplex: nic.duplex, duplex: nic.duplex,
mtu: nic.mtu, mtu: nic.mtu,
speed: nic.speed, speed: nic.speed,
dhcp: false, dhcp: getDarwinIfaceDHCPstatus(nic.iface),
dnsSuffix: '', dnsSuffix: '',
ieee8021xAuth: '', ieee8021xAuth: '',
ieee8021xState: '', ieee8021xState: '',
@ -675,7 +689,7 @@ function networkInterfaces(callback) {
dnsSuffixes = getWindowsDNSsuffixes(); dnsSuffixes = getWindowsDNSsuffixes();
} }
if (_linux) { if (_linux) {
_dhcpNics = getLinuxDHCPnNics(); _dhcpNics = getLinuxDHCPNics();
} }
for (let dev in ifaces) { for (let dev in ifaces) {
let ip4 = ''; let ip4 = '';