Skip to content

Instantly share code, notes, and snippets.

@yeoupooh
Last active December 19, 2015 23:19
Show Gist options
  • Save yeoupooh/6034322 to your computer and use it in GitHub Desktop.
Save yeoupooh/6034322 to your computer and use it in GitHub Desktop.
Get external IP address.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
public class NetUtils {
public static String getExternalIpAddress() throws IOException {
URL whatismyip = new URL("http://checkip.amazonaws.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
String ip = in.readLine(); // you get the IP as a String
in.close();
return ip;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment