dongnue2071 2015-07-10 19:43
浏览 33
已采纳

是否可以通过PHP或Apache从客户端获取网络域?

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 through IP address because it isn't trustable, only network domain/ workgroup.

For reasons unknown to me I can't have a login screen, access must be automatic and seamless.

Someone know how can I do it?

  • 写回答

1条回答 默认 最新

  • duankanjian4642 2015-07-10 19:46
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入