package com.se.system.utils;
|
|
import java.net.HttpURLConnection;
|
import java.net.InetAddress;
|
import java.net.URL;
|
|
@SuppressWarnings("ALL")
|
public class ConnectUtils {
|
public static boolean pingIp(String ip) {
|
try {
|
InetAddress inetAddress = InetAddress.getByName(ip);
|
|
return inetAddress.isReachable(1000);
|
} catch (Exception ex) {
|
return false;
|
}
|
}
|
|
public static boolean getUrl(String uri, String method) {
|
try {
|
URL url = new URL(uri);
|
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
con.setRequestMethod(method);
|
con.setConnectTimeout(1000);
|
con.setReadTimeout(1000);
|
|
int code = con.getResponseCode();
|
|
return code >= 200 && code <= 399;
|
} catch (Exception ex) {
|
return false;
|
}
|
}
|
}
|