简体   繁体   English

Java获取发布的外部IP地址?

[英]Java get published external IP Address?

I have been going through so many stackoverflow answers and none answers my question accurately. 我已经经历了很多stackoverflow答案,但没有一个答案能准确地回答我的问题。

My question is, how can I get my real internet external IP Address, not the local one, but my published IP Address which other people see & connect to? 我的问题是,如何获得我真正的Internet外部IP地址,而不是本地IP地址,而是其他人看到并连接到的我发布的IP地址?

Eg : 84.110.208.20 and not. 例如:不是84.110.208.20。 198.168.2.101 198.168.2.101

Currently im pooling the IP Address from whatismyip.com, but that takes a few seconds to get, since i have to buffer read it. 目前,我正在从whatismyip.com池中合并IP地址,但这需要花费几秒钟的时间,因为我必须缓冲读取它。

Is there a way to do it without reading the ip from a website? 有没有不从网站读取ip的方法吗?

I do not know a solution to your problem that you are asking for, but I tried out your solution and I'm not getting the same "few seconds" delay as you, so I decided to share my solution: 我不知道您要解决的问题的解决方案,但是我尝试了您的解决方案,并且没有像您一样出现“几秒钟”的延迟,所以我决定分享我的解决方案:

public static String getIp() throws IOException{
    URL whatismyip = new URL("http://icanhazip.com");
    BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
    return in.readLine();
}

Maybe whatismyip.com is slower, or has more information to parse? 也许whatismyip.com速度较慢,或者有更多信息需要解析?

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

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