docker: loop through the ip net addr output
all of a sudden, my linux box has the actual address in [1].
ip -f inet -j addr show wlp2s0
[{
"addr_info": [{}]
},{
"ifindex": 3,
"ifname": "wlp2s0",
"flags": ["BROADCAST","MULTICAST","UP","LOWER_UP"],
"mtu": 1500,
"qdisc": "mq",
"operstate": "UP",
"group": "default",
"txqlen": 1000,
"addr_info": [{
"family": "inet",
"local": "192.168.1.8",
"prefixlen": 24,
"broadcast": "192.168.1.255",
"scope": "global",
"dynamic": true,
"noprefixroute": true,
"label": "wlp2s0",
"valid_life_time": 78146,
"preferred_life_time": 78146
}]
},{
"addr_info": [{}]
},{
"addr_info": [{}]
}
]
This commit is contained in:
@@ -248,8 +248,10 @@ function getAddresses() {
|
||||
const addresses = [];
|
||||
for (const phy of physicalDevices) {
|
||||
const result = safe.JSON.parse(safe.child_process.execSync(`ip -f inet -j addr show ${phy.name}`, { encoding: 'utf8' }));
|
||||
const address = safe.query(result, '[0].addr_info[0].local');
|
||||
if (address) addresses.push(address);
|
||||
for (const r of result) {
|
||||
const address = safe.query(r, 'addr_info[0].local');
|
||||
if (address) addresses.push(address);
|
||||
}
|
||||
}
|
||||
|
||||
return addresses;
|
||||
|
||||
Reference in New Issue
Block a user