Skip to content

Instantly share code, notes, and snippets.

@azenla
Created May 16, 2013 01:18
Show Gist options
  • Save azenla/5588727 to your computer and use it in GitHub Desktop.
Save azenla/5588727 to your computer and use it in GitHub Desktop.
Simple IP address getter using Java. Is automatically compiled by Jenkins on commits.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class PublicIPGetter {
public static void main(String[] args) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL("http://bot.whatismyipaddress.com/").openConnection();
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
System.out.println("Your IP Address is: " + reader.readLine());
reader.close();
connection.disconnect();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment