public static long ping(final String host, final int port,
            final int timeoutMs) {
        long start = -1;
        long end = -1;
        long total = -1;
        final Socket s = new Socket();
        try {
            final InetAddress addr = InetAddress.getByName(host.trim());
            final InetSocketAddress sockaddr = new InetSocketAddress(addr, port);
            start = System.currentTimeMillis();
            s.connect(sockaddr, timeoutMs);
            end = System.currentTimeMillis();
        } catch (final SocketTimeoutException e) {
            IRC.log("The socket has timed out when attempting to connect!");
            IRC.log("Try running /irc reload in a few mins!");
            start = -1;
            end = -1;
            total = -1;
        } catch (final ConnectException e) {
            IRC.log("Your connection was refused by the IRC server!");
            IRC.log("Try running /irc reload in a few mins!");
            start = -1;
            end = -1;
            total = -1;
        } catch (final IOException e) {
            IRC.debug(e);
            start = -1;
            end = -1;
            total = -1;
        } finally {
            if (s != null) {
                try {
                    s.close();
                } catch (final Exception e) {
                    IRC.debug(e);
                }
            }
            if (start != -1 && end != -1) {
                total = end - start;
            }
        }
        return total;
    }