Java IP Address Get getIp()

Here you can find the source of getIp()

Description

Checks public IP address from Amazon's API

License

Open Source License

Declaration

public static String getIp() throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    /**/*from   w w w .  j ava2 s  .co  m*/
    * Checks public IP address from Amazon's API
    * 
    **/
    public static String getIp() throws IOException {
        URL whatismyip = new URL("http://checkip.amazonaws.com");
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
            String ip = in.readLine();
            return ip;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}

Related

  1. getIP()
  2. getIp()
  3. getIP()
  4. getIp()
  5. getIp()
  6. getIp()
  7. getIp()
  8. getIP()
  9. getIp()