phptcpxinetd

Xinetd obtain remote IP with PHP


Hello I have this service with xinetd:

service MyService 
{
port = 8881
socket_type = stream
wait = no
user = nobody
server = /usr/local/bin/php
server_args = /home/file/public_html/php/port/test1.php
log_on_success + = USERID
log_on_failure + = USERID
disable = no
}

My File test1.php:

<? php
$handle = fopen ('php :/ / stdin', 'r');
$input = fgets ($ handle);
fclose ($ handle);
$ip = $_SERVER['REMOTE_ADDR']
echo "Hello {$ input} your IP: $ip";
?>

I can not get the remote ip:

$ip = $ _SERVER['REMOTE_ADDR']

As I can get the remote ip??


Solution

  • The solution is modifying the PHP with :

    $IpX = $_SERVER['REMOTE_HOST'] ? $_SERVER['REMOTE_HOST'] : $_SERVER['HOST'];

    <? php
    $IpX = $_SERVER['REMOTE_HOST'] ? $_SERVER['REMOTE_HOST'] : $_SERVER['HOST'];
    $handle = fopen ('php :/ / stdin', 'r');
    $input = fgets ($ handle);
    fclose ($ handle);
    echo "Hello {$ input} your IP: $IpX";
    ?>
    

    Thanks to: Gonzalo Ayuzo