PHP |从客户端用户获取私有IP地址? [英] PHP | Get private IP address from a client user?

查看:446
本文介绍了PHP |从客户端用户获取私有IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道问题,但没有在stackoverflow上找到真正的答案。这不是 X_FORWARDED_FOR SERVER_NAME SERVER_REMOTE_ADDR ,我想要的获取连接到我的服务器的远程客户端的本地IP地址,以检测本地远程网络上的用户是否已连接。

I know question but didn't find real answer on stackoverflow. This is not X_FORWARDED_FOR, SERVER_NAME or SERVER_REMOTE_ADDR, I want get local IP address of remote client connected to my server to detect who is really on local remote network is connected.

解释:

ISP  <---->  ROUTER <----> LOCAL NETWORK <----> LOCAL PC

我想知道什么?


  1. 连接的远程客户端的公共IP地址 $ _ SERVER [REMOTE_ADDR] ,好的,但是!...

  2. 公共网络上已连接客户端的本地IP地址(192.168.xx,10.xxx,172.xxx)

  1. Public IP address of connected remote client $_SERVER["REMOTE_ADDR"], okay, but!...
  2. Local IP address of connected client on public network (192.168.x.x, 10.x.x.x, 172.x.x.x)

如何解决这个问题呢?我有回答,所以我想如果想知道本地IP地址,应该知道每个人:

How to solve this problem? I have answer, so I think this should be know for everyone if want to know local IP address:

你应该使用 CURL curl_getinfo()函数。然后,点URL地址任何你想要的人(你的主服务器IP或其他),例如:

You should use CURL and curl_getinfo() function. Then, point URL address anyone that you want (your main server ip or whatever), for example:

<?php
    $ch = curl_init();

    $opt = curl_setopt($ch, CURLOPT_URL, "YOUR_SOME_URL_ADDRESS"); 

    curl_exec($ch);

    $response = curl_getinfo($ch);

    $result = array('client_public_address' => $response["primary_ip"],
                    'client_local_address' => $response["local_ip"]
            );

    var_dump($result);

    curl_close($ch);

?>

专注于 $ response [primary_ip] 响应您的公共地址和 $ response [local_ip] ,它响应本地地址。现在这是一个例子:

Focus on $response["primary_ip"] which responses your Public address and $response["local_ip"] which reponses local address. Now this is example:

ISP  <---->  ROUTER <----> LOCAL NETWORK <----> LOCAL PC
 /\                                              /\
 ||                                              ||
 \/                                              \/
$response["primary_ip"]                  <----> $response["local_ip"]
213.x.x.x  (for example)                        192.168.1.3 (for example)

结果:

array (size=2)
  'client_public_address' => string '213.xxx.xxx.xxx' (length=14)
  'client_local_address'  => string '192.168.1.3' (length=11)

这不会给出一个真正的本地IP地址!

This will NOT be giving a REAL local IP address!

谢谢。

推荐答案

这将永远不会起作用。

首先,你需要一个客户端上的HTTP服务器来响应CURL。

即使它是 - 它也不保证返回任何本地IP。
接下来,将其客户端恢复的HTTP服务器看起来很可疑,并且很可能被禁止。

This will never get to work.
First, you need an HTTP server on a client to make it response to CURL.
Even if ther would be - it is not guarantted to return whatever "local IP". Next, an HTTP server which pings it's clients back looks suspicious and most likely gets banned.

无论如何,我在远程IP上尝试了你的代码:

Anyway, I tried your code on a remote IP:

array(2) {
  ["client_public_address"]=>
  string(7) "8.8.8.8"
  ["client_local_address"]=>
  string(0) ""
}

它什么都没有返回

当我尝试使用本地路由器时,它可以正常工作

While when I tried my local router it works okay

array(2) {
  ["client_public_address"]=>
  string(13) "XXX"
  ["client_local_address"]=>
  string(12) "192.168.1.37"
}

仅适用于对于自己的本地路由器,但它无法从远程系统获取任何本地地址。

坦率地说,它只显示分配给您PC的本地IP地址。

It works only for your own local router, but it cannot get whatever local address from a remote system.
Frankly, it shows you just local IP address assigned to your PC.

这篇关于PHP |从客户端用户获取私有IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆