fix: show server IP address in Network field instead of "Unavailable"
Three-level fallback chain: 1. gethostbyname(gethostname()) - PHP built-in, works on Linux and Windows 2. ip -4 addr show scope global | grep inet - Linux shell fallback 3. hostname -I - Linux shell secondary fallback All results validated with FILTER_VALIDATE_IP before display.
This commit is contained in:
parent
bb8ed60216
commit
a4bccc765c
|
|
@ -430,12 +430,29 @@ class SystemOperations
|
||||||
|
|
||||||
private function readNetworkStatus(): string
|
private function readNetworkStatus(): string
|
||||||
{
|
{
|
||||||
$result = $this->safeCommand('ip addr 2>/dev/null | head -n 5');
|
// Try PHP built-in first — works on Linux and Windows without shell
|
||||||
if ($result === 'Unavailable' || trim($result) === '') {
|
$hostname = gethostname();
|
||||||
return 'Unavailable';
|
if ($hostname !== false) {
|
||||||
|
$ip = gethostbyname($hostname);
|
||||||
|
// gethostbyname returns the hostname unchanged if resolution fails
|
||||||
|
if ($ip !== $hostname && filter_var($ip, FILTER_VALIDATE_IP)) {
|
||||||
|
return $ip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'Detected';
|
// Fallback: parse first non-loopback IPv4 from ip addr output
|
||||||
|
$result = $this->safeCommand("ip -4 addr show scope global | grep inet | awk '{print $2}' | cut -d/ -f1 | head -1 2>/dev/null");
|
||||||
|
if ($result !== 'Unavailable' && trim($result) !== '' && filter_var(trim($result), FILTER_VALIDATE_IP)) {
|
||||||
|
return trim($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: hostname -I
|
||||||
|
$result = $this->safeCommand('hostname -I 2>/dev/null | awk \'{print $1}\'');
|
||||||
|
if ($result !== 'Unavailable' && trim($result) !== '' && filter_var(trim($result), FILTER_VALIDATE_IP)) {
|
||||||
|
return trim($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Unavailable';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readInternetStatus(): string
|
private function readInternetStatus(): string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user