Java IP Address Get getPublicIP()

Here you can find the source of getPublicIP()

Description

get Public IP

License

Open Source License

Declaration

public static String getPublicIP() 

Method Source Code


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

import java.io.*;
import java.net.*;

public class Main {
    public static String getPublicIP() {
        String raw = downloadString("http://checkip.dyndns.org/");
        raw = raw.substring(raw.indexOf(":") + 1).trim();
        raw = raw.substring(0, raw.indexOf("<")).trim();
        return raw;
    }/*from  w  w  w  .  jav a2 s.c o  m*/

    public static String downloadString(String url) {
        String s = null;
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
            String ss;
            while ((ss = reader.readLine()) != null)
                s += ss;
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return s;
    }
}

Related

  1. getLongIp(String ipString)
  2. getPublicIP()
  3. getPublicIP()
  4. getPublicIP()
  5. getPublicIP()
  6. getPublicIP()
  7. getPublicIP2()
  8. getPublicIPAddress()
  9. getPublicIps()