i should mention im doing live tests before upload, and this is pre-maintenance, anything worth noting will be written in comments Signed-off-by: deepCurse <leverplays@gmail.com>
38 lines
927 B
Java
38 lines
927 B
Java
package pkg.deepCurse.nopalmo.utils;
|
|
|
|
import java.io.IOException;
|
|
import java.net.InetAddress;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.UnknownHostException;
|
|
import java.nio.channels.SocketChannel;
|
|
import java.util.Date;
|
|
|
|
public class UptimePing {
|
|
|
|
public static long sendPing(String IP) throws Exception {
|
|
|
|
int port = 80;
|
|
long timeToRespond = 0;
|
|
|
|
InetAddress inetAddress = InetAddress.getByName(IP);
|
|
InetSocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
|
|
|
|
SocketChannel sc = SocketChannel.open();
|
|
sc.configureBlocking(true);
|
|
|
|
Date start = new Date();
|
|
if (sc.connect(socketAddress)) {
|
|
Date stop = new Date();
|
|
timeToRespond = (stop.getTime() - start.getTime());
|
|
|
|
}
|
|
|
|
// System.out.println("fix me"); // not sure why this is here
|
|
|
|
if (socketAddress.getAddress() == null) {
|
|
return -1;
|
|
} else {
|
|
return timeToRespond;
|
|
}
|
|
}
|
|
}
|