This php function list all IP v4 addresses of the server/machine where script is executed. It works on Windows, Ubuntu and MacOSX.
function get_ipv4_addresses() {
$interfaces = array();
$regexp = '([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})';
$os = strtoupper(PHP_OS);
if ($os === 'WINNT') {
$buffer = shell_exec('ipconfig');
$pattern = "/IPv4 Address[^:]+: $regexp/";
} else {
$buffer = shell_exec('ifconfig');
$pattern = "/inet addr:\s*$regexp/";
}
if (preg_match_all($pattern, $buffer, $matches)) {
$interfaces = $matches[1];
}
return $interfaces;