1
13693261870
2024-12-06 faf8bfe6aff8e7a06adbdb63e14c3b83ef52614f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
        }
    }
}