简体   繁体   English

如何在CometD中获取客户端的代理IP地址?

[英]How to get client's Proxy IP address in CometD?

Using fiddler as a HTTP proxy, i connect to a local CometD server. 使用提琴手作为HTTP代理,我连接到本地CometD服务器。

I inherit the class DefaultSecurityPolicy , and got the client's IP address with server.getContext().getRemoteAddress().getAddress().getHostAddress() in canHandshake Method. 我继承类DefaultSecurityPolicy ,并得到了与客户端的IP地址server.getContext().getRemoteAddress().getAddress().getHostAddress()canHandshake方法。

However, it returns the client's real IP (original IP), but what i want is the one directly communicates with the server. 但是,它返回客户端的真实IP(原始IP),但是我要的是直接与服务器通信的IP。 Any help? 有什么帮助吗?


If the client using WebSocket to communicate with CometD server, The HTTP proxy doesn't take effect at all, So what i got is the original addr, am i right? 如果客户端使用WebSocket与CometD服务器进行通信,那么HTTP代理根本不会生效,那么我得到的是原始地址,对吗?

public function getlocationFromIp()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) { 
        // Check if using Shared Internet Environment 
        $ipAddress = $_SERVER['HTTP_CLIENT_IP']; 
    }elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ 
        // Check if using Proxy User 
        $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR']; 
    }else{ 
        $ipAddress = $_SERVER['REMOTE_ADDR']; 
    } 
    $ip_geo_url   = 'http://freegeoip.net/json/'.$ipAddress;
    $ip_json    = file_get_contents($ip_geo_url);
    $ip_json    = json_decode($ip_json);
    return $ip_json;
}

it will get the location whit ip if it help you ... it will be get the proxy location too 如果有帮助的话,它将获得whit ip的位置...也将获得代理位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM