java 如何获取手机的公网IP地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4385372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get a public IP address of a mobile phone?
提问by Vimal Basdeo
I want to connect my phone to a server using the internet using the server's IP address. Mobile phone's IP address are normally private as far as I came to know.. To make my app work, I need a public Ip address of my phone. How do I achieve that??
我想使用服务器的 IP 地址将我的手机连接到使用互联网的服务器。据我所知,手机的 IP 地址通常是私有的。为了使我的应用程序正常工作,我需要手机的公共 IP 地址。我如何做到这一点?
Thanks
谢谢
回答by Andreas Dolk
You'll have to wait for IPv6 ;) Now you get private address and the your service provider does some address translation (NAT): The router has one single public IP and uses ports to map incoming messages to IP addresses of the private network.
您将不得不等待 IPv6 ;) 现在您获得私有地址,您的服务提供商会进行一些地址转换 (NAT):路由器有一个公共 IP,并使用端口将传入消息映射到私有网络的 IP 地址。
Your mobile's IP is invisible to the internet and the networks public IP is useless, because it is the router's address. Maybe with IPv6 we have public IPs for all mobiles, but for now you'll have to find a different solution for your problem - public IP doesn't work with mobiles as with all other clients in private networks (behind routers).
您手机的 IP 对互联网是不可见的,网络公共 IP 没有用,因为它是路由器的地址。也许对于 IPv6,我们有适用于所有移动设备的公共 IP,但现在您必须为您的问题找到不同的解决方案 - 公共 IP 不适用于移动设备,就像专用网络中的所有其他客户端(在路由器后面)一样。
回答by rapadura
Setup your own hosting server, make your app "goto" that server, fetch a simple txt page, in that simple txt you dynamically on the server set the address that was used to get the txt.
设置您自己的托管服务器,让您的应用“转到”该服务器,获取一个简单的 txt 页面,在该简单 txt 中,您在服务器上动态设置用于获取 txt 的地址。
Example:
例子:
Server: yourexample.com url for /ip.php ip.php just respondes with mimetype text and the address of the requesting client.
服务器:yourexample.com url for /ip.php ip.php 只响应 mimetype 文本和请求客户端的地址。
J2ME: Request yourexample/ip.php in the repsonse is the address of your app.
J2ME:在响应中请求 yourexample/ip.php 是您的应用程序的地址。
回答by david collier
astonishingly - t-mobile 3g service seems to assign a public IP. I'm still looking into the details, but I've seen an internet-available website running on a tethered laptop
令人惊讶的是 - t-mobile 3g 服务似乎分配了一个公共 IP。我仍在调查细节,但我已经看到一个互联网可用的网站运行在系留笔记本电脑上
回答by cleophus_p
You should get your i/p address. Open your browser and enter http://whatismyipaddress.com/or wait till you have You'll have to wait for IPv6
你应该得到你的 i/p 地址。打开浏览器并输入http://whatismyipaddress.com/或等到你有你必须等待 IPv6