Java InetAddress Check isPortOpen(InetAddress address, int port)

Here you can find the source of isPortOpen(InetAddress address, int port)

Description

is Port Open

License

Open Source License

Declaration

private static boolean isPortOpen(InetAddress address, int port) 

Method Source Code

//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
                }
            }
        }
    }
}

Related

  1. isLoopbackIp(InetAddress addr)
  2. isMulticastAddress(InetAddress ipAddr)
  3. isOnNetwork(InetAddress host, InetAddress network, byte[] mask)
  4. isPortFree(int port, InetAddress addr)
  5. isPortInUse(InetAddress address, int port, int count)
  6. isPrivate(InetAddress addr)
  7. isPrivate(InetAddress adr)
  8. isPrivateIp(final InetAddress address)
  9. isPrivateIp(InetAddress addr)