Fixed return of IPv4 or IPv6 address

This commit is contained in:
bergware
2018-04-05 12:47:20 +02:00
parent f4c5a26771
commit 70b5308463
@@ -796,11 +796,8 @@ class DockerUtil {
}
public static function myIP($name, $version=4) {
$networks = explode('|', DockerUtil::docker("inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}|{{end}}' $name"));
foreach ($networks as $network) {
if ($version==4 && strpos($network,'.')!==false) return $network;
if ($version==6 && strpos($network,':')!==false) return $network;
}
$ipaddr = $version==4 ? 'IPAddress' : 'GlobalIPv6Address';
return DockerUtil::docker("inspect --format='{{range .NetworkSettings.Networks}}{{.$ipaddr}}{{end}}' $name");
}
}
?>