Last active
December 19, 2015 23:19
-
-
Save yeoupooh/6034322 to your computer and use it in GitHub Desktop.
Get external IP address.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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