networkConnections(): added process name (mac OS)
This commit is contained in:
parent
2e1cfb0a68
commit
1001e1e14c
@ -56,6 +56,7 @@ We had to make **several interface changes** to keep systeminformation as consis
|
||||
- `graphics()`: extended properties (mac OS)
|
||||
- `graphics()`: extended nvidia-smi parsing
|
||||
- `networkInterfaces()`: type detection improved (win - wireless)
|
||||
- `networkConnections()`: added process name (mac OS)
|
||||
- `memLayout()`: extended manufacturer list (decoding)
|
||||
- `memLayout()`: added ECC flag
|
||||
- `osInfo()`: better fqdn (win)
|
||||
@ -80,6 +81,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
|
||||
|
||||
| Version | Date | Comment |
|
||||
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
|
||||
| 5.13.0 | 2022-11-17 | `networkConnections()` addedd process name (mac OS) |
|
||||
| 5.12.15 | 2022-11-16 | `networkConnections()` adapted parsing to reflect also UDP (mac OS) |
|
||||
| 5.12.14 | 2022-11-11 | restored `powershell` compatibility for version 7.3 (windows) |
|
||||
| 5.12.13 | 2022-11-06 | updated docs |
|
||||
|
||||
@ -112,6 +112,7 @@ si.cpu()
|
||||
|
||||
(last 7 major and minor version releases)
|
||||
|
||||
- Version 5.13.0: `networkConnections()` added process name (mac OS)
|
||||
- Version 5.12.0: `cpu()` added performance and efficiency cores
|
||||
- Version 5.11.0: `networkInterfaces()` added default property and default parameter
|
||||
- Version 5.10.0: basic `android` support
|
||||
@ -595,7 +596,7 @@ Full function reference with examples can be found at [https://systeminformation
|
||||
| | [0].peerPort | X | X | X | X | | peer port |
|
||||
| | [0].state | X | X | X | X | | like ESTABLISHED, TIME_WAIT, ... |
|
||||
| | [0].pid | X | X | X | X | | process ID |
|
||||
| | [0].process | X | X | | | | process name |
|
||||
| | [0].process | X | X | X | | | process name |
|
||||
| si.inetChecksite(url, cb) | {...} | X | X | X | X | X | response-time (ms) to fetch given URL |
|
||||
| | url | X | X | X | X | X | given url |
|
||||
| | ok | X | X | X | X | X | status code OK (2xx, 3xx) |
|
||||
|
||||
@ -57,6 +57,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">5.13.0</th>
|
||||
<td>2022-11-17</td>
|
||||
<td><span class="code">networkConnections()</span> added process name (mac OS)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">5.12.15</th>
|
||||
<td>2022-11-16</td>
|
||||
|
||||
@ -170,7 +170,7 @@
|
||||
<img class="logo" src="assets/logo.png" alt="logo">
|
||||
<div class="title">systeminformation</div>
|
||||
<div class="subtitle"><span id="typed"></span> </div>
|
||||
<div class="version">New Version: <span id="version">5.12.15</span></div>
|
||||
<div class="version">New Version: <span id="version">5.13.0</span></div>
|
||||
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
|
||||
</div>
|
||||
<div class="down">
|
||||
|
||||
@ -643,7 +643,7 @@ setInterval(function() {
|
||||
<td>[0].process</td>
|
||||
<td>X</td>
|
||||
<td>X</td>
|
||||
<td></td>
|
||||
<td>X</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>process name</td>
|
||||
|
||||
@ -1088,7 +1088,7 @@ function cpuTemperature(callback) {
|
||||
}
|
||||
} else if (section === 'pch') {
|
||||
// chipset temp
|
||||
if (firstPart.indexOf('TEMP') !== -1) {
|
||||
if (firstPart.indexOf('TEMP') !== -1 && !result.chipset) {
|
||||
result.chipset = parseFloat(temps);
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,7 +339,7 @@ function parseBlk(lines) {
|
||||
'physical': (disk.type === 'disk' ? (disk.rota === '0' ? 'SSD' : 'HDD') : (disk.type === 'rom' ? 'CD/DVD' : '')),
|
||||
'uuid': disk.uuid,
|
||||
'label': disk.label,
|
||||
'model': disk.model,
|
||||
'model': (disk.model || '').trim(),
|
||||
'serial': disk.serial,
|
||||
'removable': disk.rm === '1',
|
||||
'protocol': disk.tran,
|
||||
|
||||
102
lib/network.js
102
lib/network.js
@ -1369,6 +1369,22 @@ exports.networkStats = networkStats;
|
||||
// --------------------------
|
||||
// NET - connections (sockets)
|
||||
|
||||
function getProcessName(processes, pid) {
|
||||
let cmd = '';
|
||||
processes.forEach(line => {
|
||||
const parts = line.split(' ');
|
||||
const id = parseInt(parts[0], 10) || -1;
|
||||
if (id === pid) {
|
||||
parts.shift();
|
||||
cmd = parts.join(' ').split(':')[0];
|
||||
}
|
||||
});
|
||||
cmd = cmd.split(' -')[0];
|
||||
// return cmd;
|
||||
const cmdParts = cmd.split('/');
|
||||
return cmdParts[cmdParts.length - 1];
|
||||
}
|
||||
|
||||
function networkConnections(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
@ -1411,7 +1427,7 @@ function networkConnections(callback) {
|
||||
peerPort: peerport,
|
||||
state: connstate,
|
||||
pid: proc[0] && proc[0] !== '-' ? parseInt(proc[0], 10) : null,
|
||||
process: proc[1] ? proc[1].split(' ')[0] : ''
|
||||
process: proc[1] ? proc[1].split(' ')[0].split(':')[0] : ''
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -1453,7 +1469,7 @@ function networkConnections(callback) {
|
||||
if (line.length >= 7 && line[6].indexOf('users:') > -1) {
|
||||
let proc = line[6].replace('users:(("', '').replace(/"/g, '').split(',');
|
||||
if (proc.length > 2) {
|
||||
process = proc[0].split(' ')[0];
|
||||
process = proc[0].split(' ')[0].split(':')[0];
|
||||
pid = parseInt(proc[1], 10);
|
||||
}
|
||||
}
|
||||
@ -1486,49 +1502,53 @@ function networkConnections(callback) {
|
||||
const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT2|TIME_WAIT|CLOSE|CLOSE_WAIT|LAST_ACK|LISTEN|CLOSING|UNKNOWN';
|
||||
exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
exec('ps -axo pid,command', { maxBuffer: 1024 * 20000 }, function (err2, stdout2) {
|
||||
let processes = stdout2.toString().split('\n');
|
||||
processes = processes.map((line => { return line.trim().replace(/ +/g, ' '); }));
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
lines.forEach(function (line) {
|
||||
line = line.replace(/ +/g, ' ').split(' ');
|
||||
if (line.length >= 8) {
|
||||
let localip = line[3];
|
||||
let localport = '';
|
||||
let localaddress = line[3].split('.');
|
||||
if (localaddress.length > 1) {
|
||||
localport = localaddress[localaddress.length - 1];
|
||||
localaddress.pop();
|
||||
localip = localaddress.join('.');
|
||||
}
|
||||
let peerip = line[4];
|
||||
let peerport = '';
|
||||
let peeraddress = line[4].split('.');
|
||||
if (peeraddress.length > 1) {
|
||||
peerport = peeraddress[peeraddress.length - 1];
|
||||
peeraddress.pop();
|
||||
peerip = peeraddress.join('.');
|
||||
}
|
||||
const hasState = states.indexOf(line[5]) >= 0;
|
||||
let connstate = hasState ? line[5] : 'UNKNOWN';
|
||||
let pid = parseInt(line[8 + (hasState ? 0 : -1)], 10);
|
||||
if (connstate) {
|
||||
result.push({
|
||||
protocol: line[0],
|
||||
localAddress: localip,
|
||||
localPort: localport,
|
||||
peerAddress: peerip,
|
||||
peerPort: peerport,
|
||||
state: connstate,
|
||||
pid: pid,
|
||||
process: ''
|
||||
});
|
||||
lines.forEach(function (line) {
|
||||
line = line.replace(/ +/g, ' ').split(' ');
|
||||
if (line.length >= 8) {
|
||||
let localip = line[3];
|
||||
let localport = '';
|
||||
let localaddress = line[3].split('.');
|
||||
if (localaddress.length > 1) {
|
||||
localport = localaddress[localaddress.length - 1];
|
||||
localaddress.pop();
|
||||
localip = localaddress.join('.');
|
||||
}
|
||||
let peerip = line[4];
|
||||
let peerport = '';
|
||||
let peeraddress = line[4].split('.');
|
||||
if (peeraddress.length > 1) {
|
||||
peerport = peeraddress[peeraddress.length - 1];
|
||||
peeraddress.pop();
|
||||
peerip = peeraddress.join('.');
|
||||
}
|
||||
const hasState = states.indexOf(line[5]) >= 0;
|
||||
let connstate = hasState ? line[5] : 'UNKNOWN';
|
||||
let pid = parseInt(line[8 + (hasState ? 0 : -1)], 10);
|
||||
if (connstate) {
|
||||
result.push({
|
||||
protocol: line[0],
|
||||
localAddress: localip,
|
||||
localPort: localport,
|
||||
peerAddress: peerip,
|
||||
peerPort: peerport,
|
||||
state: connstate,
|
||||
pid: pid,
|
||||
process: getProcessName(processes, pid)
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user