読んだ後: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);
}
私は勝者だと思っていましたが、次のエラーが発生します
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)
これは、サーバーが十分な速度で応答していないためだと思いますが、外部IPを確実に取得する方法はありますか?
編集:大丈夫なので拒否されます、他の誰かが同じ機能を実行できる別のサイトを知っています