java中远程客户端的本地网络IP地址

发布于 2024-09-26 16:31:10 字数 46 浏览 0 评论 0原文

有谁知道如何用java从远程客户端获取本地网络IP地址?

谢谢

Does anyone know how to get the Local Net Ip Address from a Remote Client in java?

thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘你却要生生世世 2024-10-03 16:31:10

这是您要找的吗?

InetAddress addr = InetAddress.getLocalHost();
byte[] ipAddr = addr.getAddress(); // Get IP Address
String hostname = addr.getHostName(); // Get hostname

它获取运行代码的机器的 IP。

Is this what you are looking for?

InetAddress addr = InetAddress.getLocalHost();
byte[] ipAddr = addr.getAddress(); // Get IP Address
String hostname = addr.getHostName(); // Get hostname

That gets the IP of the machine the code is running on.

苏别ゝ 2024-10-03 16:31:10

假设您的意思是获取在 NAT 之后运行的客户端的本地 IP 地址,则您只能在客户端的配合下才能做到这一点,这意味着您必须自己发送它。

无论如何,你需要它做什么?

Assuming you mean getting the local IP address of a client running behind NAT, you can only do that with the client's cooperation, meaning you have to send it yourself.

What do you need it for anyway?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文