Here you can find the source of pingUrl(final String address)
public static boolean pingUrl(final String address)
//package com.java2s; //License from project: Open Source License import java.net.*; public class Main { public static boolean pingUrl(final String address) { try {/*ww w . ja va 2 s. co m*/ final URL url = new URL("http://" + address); final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); urlConn.setConnectTimeout(3000); final long startTime = System.currentTimeMillis(); urlConn.connect(); final long endTime = System.currentTimeMillis(); if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) { System.out.println("Time (ms) : " + (endTime - startTime)); System.out.println("Ping to " + address + " was success"); return true; } } catch (final Exception e1) { e1.printStackTrace(); } return false; } }