get dhcp status from linux
This commit is contained in:
parent
73a2ad62b1
commit
fca0920652
@ -318,30 +318,46 @@ function getDarwinNics() {
|
||||
}
|
||||
|
||||
|
||||
function getNicDHCPstatus(interfaceName) {
|
||||
const cmd = `nmcli con sh "${interfaceName}" | grep ipv4.method`;
|
||||
console.log(cmd);
|
||||
function getInterfaceConnectionName(interfaceName) {
|
||||
const cmd = `nmcli device status | grep ${interfaceName}`;
|
||||
|
||||
try {
|
||||
let dhcpStatus = "";
|
||||
const lines = execSync(cmd, util.execOptsWin).toString().split('\n');
|
||||
const nsections = splitSectionsNics(lines);
|
||||
console.log(nsections);
|
||||
switch (key) {
|
||||
case "auto":
|
||||
dhcpStatus = "true";
|
||||
const result = execSync(cmd).toString();
|
||||
const resultFormat = result.replace(/\s+/g,' ').trim();
|
||||
const connectionNameLines = resultFormat.split(" ").slice(3);
|
||||
const connectionName = connectionNameLines.join(' ');
|
||||
return connectionName != '--' ? connectionName : '';
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function getDHCPstatus(connectionName) {
|
||||
const cmd = `nmcli connection show "${connectionName}" \| grep ipv4.method;`;
|
||||
try {
|
||||
console.log(1);
|
||||
const result = execSync(cmd).toString();
|
||||
console.log(2);
|
||||
const resultFormat = result.replace(/\s+/g,' ').trim();
|
||||
|
||||
let dhcStatus = resultFormat.split(" ").slice(1).toString();
|
||||
switch (dhcStatus) {
|
||||
case 'auto':
|
||||
dhcStatus = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
dhcpStatus = "false";
|
||||
dhcStatus = false;
|
||||
break;
|
||||
}
|
||||
return dhcpStatus;
|
||||
return dhcStatus;
|
||||
} catch (e) {
|
||||
return [];
|
||||
return 'Unknow';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function testVirtualNic(iface, ifaceName, mac) {
|
||||
const virtualMacs = ['00:00:00:00:00:00', '00:03:FF', '00:05:69', '00:0C:29', '00:0F:4B', '00:0F:4B', '00:13:07', '00:13:BE', '00:15:5d', '00:16:3E', '00:1C:42', '00:21:F6', '00:21:F6', '00:24:0B', '00:24:0B', '00:50:56', '00:A0:B1', '00:E0:C8', '08:00:27', '0A:00:27', '18:92:2C', '16:DF:49', '3C:F3:92', '54:52:00', 'FC:15:97'];
|
||||
if (mac) {
|
||||
@ -370,8 +386,6 @@ function networkInterfaces(callback) {
|
||||
|
||||
nics.forEach(nic => {
|
||||
|
||||
dhcpStatus = getNicDHCPstatus(nic.iface);
|
||||
|
||||
result.push({
|
||||
iface: nic.iface,
|
||||
ifaceName: nic.iface,
|
||||
@ -383,7 +397,6 @@ function networkInterfaces(callback) {
|
||||
operstate: nic.operstate,
|
||||
type: nic.type,
|
||||
duplex: nic.duplex,
|
||||
dhcpStatus: dhcpStatus,
|
||||
mtu: nic.mtu,
|
||||
speed: nic.speed,
|
||||
carrierChanges: 0
|
||||
@ -461,12 +474,17 @@ function networkInterfaces(callback) {
|
||||
echo -n "speed: "; cat /sys/class/net/${iface}/speed 2>/dev/null; echo;
|
||||
echo -n "tx_queue_len: "; cat /sys/class/net/${iface}/tx_queue_len 2>/dev/null; echo;
|
||||
echo -n "type: "; cat /sys/class/net/${iface}/type 2>/dev/null; echo;
|
||||
echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null \| grep ${iface}; echo
|
||||
echo -n "wireless: "; cat /proc/net/wireless 2>/dev/null \| grep ${iface}; echo;
|
||||
echo -n "wirelessspeed: "; iw dev ${iface} link 2>&1 \| grep bitrate; echo;`;
|
||||
let lines = [];
|
||||
|
||||
let lines = [];
|
||||
|
||||
try {
|
||||
const connectionName = getInterfaceConnectionName(iface);
|
||||
dhcp = getDHCPstatus(connectionName);
|
||||
lines = execSync(cmd).toString().split('\n');
|
||||
|
||||
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user