How to get external IP successfully

前端 未结 9 1262
耶瑟儿~
耶瑟儿~ 2020-12-03 16:16

After reading: Getting the 'external' IP address in Java

code:

public static void main(String[] args) throws IOException
{
    URL whatismyip         


        
9条回答
  •  旧巷少年郎
    2020-12-03 17:09

        public static void main(String[] args) throws IOException 
        {
        URL connection = new URL("http://checkip.amazonaws.com/");
        URLConnection con = connection.openConnection();
        String str = null;
        BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
        str = reader.readLine();
        System.out.println(str);
         }
    

提交回复
热议问题