Is it possible to get Network Domain from Client with PHP or Apache?

前端 未结 1 1856
迷失自我
迷失自我 2021-01-16 20:49

I\'m working on a solution to identify client Network Domain or Workgroup in a private network. Based on it, I must change some access permissions.

I can\'t do that

相关标签:
1条回答
  • 2021-01-16 20:59

    It's possible to get corresponding to a given IP address using gethostbyaddr function http://php.net/manual/en/function.gethostbyaddr.php:

        $proxy = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : false;
    
    if(!!$proxy){
    $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
         echo "Warning: Your cliend is using proxy, may could not determine hostname";
        }else{
        $ipaddress = $_SERVER['REMOTE_ADDR']; //
        }
        $hostname = gethostbyaddr($ipaddress); //Its will return domain + machine-name inside a private network.
    
        if($ipaddress  == $hostname){
         echo "Impossible to determine hostname for: ", $ipaddress ;
        }else{
          echo "The hostname for ", $ipaddress, "is : ",  $hostname;
        }
    

    But the communication using application / session layer to network layer is a little complicated. You must don't trust it to access control in php applications.

    To get all public IP Address is possible to use WebRTC (javascript) instead remote addrees from http header.

    0 讨论(0)
提交回复
热议问题