0

I need to monitor multiple ports of multiple servers using TCP syn. For example, send TCP syn to these ports every 60 seconds, to check those port open or closed.

I tried java socket.connect and nmap

try {
    socket.connect(socketAddress, timeout);
    socket.close();
    System.out.println("port is open");
} catch (IOException e) {
    System.out.println("port is closed");
}

The problems are java socket.connect is not TCP syn scan. Nmap can do it, but the project does not allow download other software. Do I want to know if there is any way to implement TCP syn scan using java code?

bugfreerammohan
  • 1,471
  • 1
  • 7
  • 22
frank
  • 11
  • 3
  • Reference [this](https://serverfault.com/questions/309052/check-if-port-is-open-or-closed-on-a-linux-server) – TongChen Jan 08 '19 at 06:06

1 Answers1

0

As far as I know,JDK do not support doing this.Perhaps you can use JNI and call some C++/C function.Or Use jpcap. http://jpcap.sourceforge.net/

Dar Gar
  • 26
  • 2
  • I will try ipcap to see if I can solve this problem, thank you for your reply. – frank Jan 08 '19 at 06:12
  • I can't get the jpcap package from the maven repository. It's does’t work – frank Jan 08 '19 at 06:19
  • Jpcap is a Java class package that allows Java applications to capture and/or send packets to the network. Jpcap is based on libpcap/winpcap and Raw Socket API. Therefore, Jpcap is supposed to work on any OS on which libpcap/winpcap has been implemented. If you chosse to use jpcap,you have to install linpcap(linux,mac) or winpcap(windows) first. – Dar Gar Jan 08 '19 at 06:58