AlanGomes

Untitled

Mar 24th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. public String getServerIP() {
  2. String urlloc="http://checkip.amazonaws.com/";
  3. try {
  4.           URL url = new URL(urlloc);
  5.           URLConnection openConnection = url.openConnection();    
  6.             openConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
  7.           Scanner r = new Scanner(openConnection.getInputStream());
  8.           StringBuilder sb = new StringBuilder();
  9.           while (r.hasNext()) {
  10.             sb.append(r.next());
  11.           }
  12.           r.close();
  13.           return sb.toString();
  14.         } catch (IOException e) {
  15.         }
  16. return null;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment