ping an Address - Java Network

Java examples for Network:Ping

Description

ping an Address

Demo Code


//package com.java2s;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

public class Main {
    @SuppressWarnings("resource")
    public static boolean ping(String address, int port) {
        InetSocketAddress isa = new InetSocketAddress(address, port);
        Socket connection = new Socket();
        try {// www . j  a  v a  2  s  .co m
            connection.connect(isa, 5 * 1000);
        } catch (IOException e) {
            return false;
        }

        return true;
    }
}

Related Tutorials