Update src/index.php

This commit is contained in:
2024-02-21 17:53:58 +08:00
parent 02862bfa4f
commit 9c37e20655

View File

@@ -1,12 +1,23 @@
// src/index.php // src/index.php
<?php <?php
echo '<h1>Hello World</h1><BR>';
echo 'Version: 20240221-1537<BR>';
// Creating a variable to store the $gw = "Unknown";
// server address
$ip_server = $_SERVER['SERVER_ADDR'];
// Printing the stored address // Get the Docker host IP from the routing table
echo "Server IP Address is: $ip_server"; $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";
?> ?>