From 9c37e20655fe7e1970b1bebf72b96e1f4f420a78 Mon Sep 17 00:00:00 2001 From: administrator Date: Wed, 21 Feb 2024 17:53:58 +0800 Subject: [PATCH] Update src/index.php --- src/index.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/index.php b/src/index.php index e1dc5b5..4dcc310 100644 --- a/src/index.php +++ b/src/index.php @@ -1,12 +1,23 @@ // src/index.php Hello World
'; -echo 'Version: 20240221-1537
'; -// Creating a variable to store the -// server address -$ip_server = $_SERVER['SERVER_ADDR']; - -// Printing the stored address -echo "Server IP Address is: $ip_server"; +$gw = "Unknown"; + +// Get the Docker host IP from the routing table +$table = file("/proc/net/route"); +foreach ($table as $row) { + // Split the fields out of the routing table + $fields = preg_split("/[\t ]+/", trim($row)); + + // Skip this route if it's not the default gateway + if ($fields[1] != "00000000") continue; + + // Convert the hex gateway IP to dotted-notation + $gw_hex = $fields[2]; + $gw_rev = long2ip(hexdec("0x$gw_hex")); + $gw = implode(".", array_reverse(explode(".", $gw_rev))); + break; +} + +echo "Docker host IP: $gw\n"; ?> \ No newline at end of file