Here you can find the source of isPortOpen(InetAddress address, int port)
private static boolean isPortOpen(InetAddress address, int port)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; public class Main { private static boolean isPortOpen(InetAddress address, int port) { Socket socket = null;//from w w w . j a v a 2 s. c om try { socket = new Socket(); socket.connect(new InetSocketAddress(address, port), 1000); return true; } catch (IOException e) { return false; } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { // noop } } } } }