阅读后:用Java获取"外部"IP地址
码:
public static void main(String[] args) throws IOException
{
URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp");
BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
String ip = in.readLine(); //you get the IP as a String
System.out.println(ip);
}
Run Code Online (Sandbox Code Playgroud)
我以为我是胜利者,但我得到以下错误
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: http://automation.whatismyip.com/n09230945.asp
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at getIP.main(getIP.java:12)
Run Code Online (Sandbox Code Playgroud)
我认为这是因为服务器没有足够快的响应,无论如何确保它将获得外部IP?
编辑:好吧所以它被拒绝,其他人都知道另一个可以做同样功能的网站