mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 08:34:39 +00:00
Updated guess_interface_from_ip to more accurately identify the interface using the subnet with the largest mask in the route table. (#5281)
This commit is contained in:
parent
a137d96af8
commit
ab5cbcd3ca
@ -3773,14 +3773,25 @@ function guess_interface_from_ip($ipaddress)
|
||||
|
||||
/* create a route table we can search */
|
||||
exec("/usr/bin/netstat -rnWf " . $family, $output, $ret);
|
||||
|
||||
/* search for the route with the largest subnet mask */
|
||||
$largest_mask = 0;
|
||||
$best_if = null;
|
||||
foreach ($output as $line) {
|
||||
$fields = preg_split("/\s+/", $line);
|
||||
if (is_subnet($fields[0])) {
|
||||
if (ip_in_subnet($ipaddress, $fields[0])) {
|
||||
return $fields[5];
|
||||
list($ip, $mask) = explode('/', $fields[0]);
|
||||
if ($mask > $largest_mask) {
|
||||
$best_if = $fields[5];
|
||||
$largest_mask = $mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($best_if)) {
|
||||
return $best_if;
|
||||
}
|
||||
|
||||
$ret = exec_command("/sbin/route -n get {$ipaddress} | /usr/bin/awk '/interface/ { print \$2; };'");
|
||||
if (empty($ret)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user