Skip to content

Commit

Permalink
fix time(), networkConnections() fixed wrond PID parsing (macOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Dec 12, 2024
1 parent edba2b3 commit 7fd3e4c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.

| Version | Date | Comment |
| ------- | ---------- | --------------------------------------------------------------------------------------------------- |
| 5.23.11 | 2024-12-13 | `networkConnections()` fixed wrond PID parsing (macOS) |
| 5.23.10 | 2024-12-12 | `time()` changed retrieval of timezones (linux, macOS) |
| 5.23.9 | 2024-12-11 | `typings` added definitions with overload |
| 5.23.8 | 2024-12-10 | `system()` added Raspberry 500 detection |
Expand Down
5 changes: 5 additions & 0 deletions docs/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ <h3>Full version history</h3>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.23.11</th>
<td>2024-12-13</td>
<td><span class="code">networkConnections()</span> fixed wrong PID parsing (macOS)</td>
</tr>
<tr>
<th scope="row">5.23.10</th>
<td>2024-12-12</td>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>&nbsp;</div>
<div class="version">New Version: <span id="version">5.23.10</span></div>
<div class="version">New Version: <span id="version">5.23.11</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">
Expand Down
2 changes: 1 addition & 1 deletion lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ function networkConnections(callback) {
if (_darwin) {
// let cmd = 'netstat -natv | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"';
let cmd = 'netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"';
const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT2|TIME_WAIT|CLOSE|CLOSE_WAIT|LAST_ACK|LISTEN|CLOSING|UNKNOWN';
const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT_1|FIN_WAIT2|FIN_WAIT_2|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) {
Expand Down
44 changes: 26 additions & 18 deletions lib/osinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,34 @@ const _sunos = (_platform === 'sunos');

function time() {
let t = new Date().toString().split(' ');
const result = {
current: Date.now(),
uptime: os.uptime(),
timezone: (t.length >= 7) ? t[5] : '',
timezoneName: Intl ? Intl.DateTimeFormat().resolvedOptions().timeZone : (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''
};
if (_darwin || _linux) {
const stdout = execSync('date +%Z && date +%z && ls -l /etc/localtime 2>/dev/null', util.execOptsLinux);
const lines = stdout.toString().split(os.EOL);
if (lines.length > 3 && !lines[0]) {
lines.shift();
try {
const stdout = execSync('date +%Z && date +%z && ls -l /etc/localtime 2>/dev/null', util.execOptsLinux);
const lines = stdout.toString().split(os.EOL);
if (lines.length > 3 && !lines[0]) {
lines.shift();
}
let timezone = lines[0] || '';
if (timezone.startsWith('+') || timezone.startsWith('-')) {
timezone = 'GMT';
}
return {
current: Date.now(),
uptime: os.uptime(),
timezone: lines[1] ? timezone + lines[1] : timezone,
timezoneName: lines[2] && lines[2].indexOf('/zoneinfo/') > 0 ? (lines[2].split('/zoneinfo/')[1] || '') : ''
};
} catch (e) {
util.noop();
}
return {
current: Date.now(),
uptime: os.uptime(),
timezone: lines[0] && lines[1] ? lines[0] + lines[1] : '',
timezoneName: lines[2] && lines[2].indexOf('/zoneinfo/') > 0 ? (lines[2].split('/zoneinfo/')[1] || '') : ''
};
} else {
return {
current: Date.now(),
uptime: os.uptime(),
timezone: (t.length >= 7) ? t[5] : '',
timezoneName: Intl ? Intl.DateTimeFormat().resolvedOptions().timeZone : (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''
};
};
}
return result;
}

exports.time = time;
Expand Down

0 comments on commit 7fd3e4c

Please sign in to comment.