package org.arpit.java2blog.client;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* @author java2blog.com
*
*/
public class CheckPingStatusOfURLMain {
public static void main(String args[]) throws Exception {
String status1 = getStatus("https://www.java2blog.com");
System.out.println("Java2blog.com is : " + status1);
String status2 = getStatus("http://www.javablog2.com");
System.out.println("javablog2.com is : " + status2);
}
public static String getStatus(String url) throws IOException {
String result = "";
try {
URL urlObj = new URL(url);
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
con.setRequestMethod("GET");
// Set connection timeout
con.setConnectTimeout(3000);
con.connect();
int code = con.getResponseCode();
if (code == 200) {
result = "On";
}
} catch (Exception e) {
result = "Off";
}
return result;
}
}