xaing'fa'shi当namp对一台电脑开始扫描时,我能探测到,在namp进行SYN,Null,Xmas扫描的时候是发送SYN包,空标志位包,Fin
等各种包,java有没有办法获取tcp连接中的包呢,非常迷。。。。。
import java.io.IOException;
import java.net.Socket;
public class NmapDetection {
public static boolean isNmapScanning(String host, int[] ports) {
for (int port : ports) {
try (Socket socket = new Socket(host, port)) {
// 如果连接成功,表示该端口被打开,可能被nmap扫描
System.out.println("Port " + port + " is open");
return true;
} catch (IOException e) {
// 如果连接失败,表示该端口被关闭或被防火墙保护
System.out.println("Port " + port + " is closed");
}
}
return false;
}
public static void main(String[] args) {
String host = "your-host";
int[] ports = {80, 443, 8080}; // 常见的HTTP/HTTPS端口
boolean isScanned = isNmapScanning(host, ports);
if (isScanned) {
System.out.println("Detected nmap scanning");
} else {
System.out.println("No nmap scanning detected");
}
}
}