当客户端通过单元进行联机时,远程 IP 地址会有所不同


Remote IP address varies when client is tethered over cell

我正在用php构建一个解决方案,这需要我准确地知道请求者的ip。 在大多数情况下,经典调用

$ip = $_SERVER['REMOTE_HOST'];

工作得很好。

但是,我

注意到,在客户端通过联机连接发出请求的情况下,我得到的地址与谷歌和我的防火墙报告的地址完全不同。

我可以通过在谷歌上搜索"我的 ip"在客户端(系留)端验证这一点,这给了我一个与我的服务器防火墙报告的 IP 相匹配的 IP。 不过,这些都与服务器端包含的$_SERVER['REMOTE_HOST']不匹配。

那么我的问题是:

  • 为什么这些地址通常不同?
  • 如何访问我的防火墙和谷歌看到的IP地址,特别是使用php?

thast取决于您的手机提供商。通常情况下,您的手机会从专用范围获取IP地址,并在"连接到互联网"时获得NAT-就像大多数家庭网络一样。

与家庭网络不同,提供商的网络可能有多个连接到互联网的连接(网关)。因此,您建立的每个连接都可能通过不同的网关。因此,您会在不同的呼叫中看到不同的地址。

在这些情况下(具有多个上行链路的网络),路由规则可能非常复杂。因此,例如,目标可能扮演一个角色 - 提供商可能在几个不同的地方(网络节点)对等互连,并选择最接近目的地的地方。因此,您可以在一个目的地上拥有一致的来源,但在另一个目的地上拥有不同的来源。

在任何情况下,您都不能对这些地址执行任何操作,因为提供商不允许任何传入连接。

他们很可能正在使用您无法控制的代理服务器。如果是这种情况,基础客户端 IP 将不可见。

呵,事实证明,这一直是使用javascript"功能"(我认为称之为漏洞)来完成的。 可怕的东西,因为它也会暴露您的内部IP地址。无论如何,它是一个名为WebRTC的东西,本周刚刚开始受到很多关注,因为它已被Firefox和chrome正式实现:

//get the IP addresses associated with an account
function getIPs(callback){
    var ip_dups = {};
    //compatibility for firefox and chrome
    var RTCPeerConnection = window.RTCPeerConnection
        || window.mozRTCPeerConnection
        || window.webkitRTCPeerConnection;
    var mediaConstraints = {
        optional: [{RtpDataChannels: true}]
    };
    //firefox already has a default stun server in about:config
    //    media.peerconnection.default_iceservers =
    //    [{"url": "stun:stun.services.mozilla.com"}]
    var servers = undefined;
    //add same stun server for chrome
    if(window.webkitRTCPeerConnection)
        servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
    //construct a new RTCPeerConnection
    var pc = new RTCPeerConnection(servers, mediaConstraints);
    //listen for candidate events
    pc.onicecandidate = function(ice){
        //skip non-candidate events
        if(ice.candidate){
            //match just the IP address
            var ip_regex = /([0-9]{1,3}('.[0-9]{1,3}){3})/
            var ip_addr = ip_regex.exec(ice.candidate.candidate)[1];
            //remove duplicates
            if(ip_dups[ip_addr] === undefined)
                callback(ip_addr);
            ip_dups[ip_addr] = true;
        }
    };
    //create a bogus data channel
    pc.createDataChannel("");
    //create an offer sdp
    pc.createOffer(function(result){
        //trigger the stun server request
        pc.setLocalDescription(result, function(){});
    }, function(){});
}
//Test: Print the IP addresses into the console
getIPs(function(ip){console.log(ip);});

来源: https://github.com/diafygi/webrtc-ips

演示:https://diafygi.github.io/webrtc-ips/