gpt4 book ai didi

java - 如何检测 Servlet 内的 ping?

转载 作者:行者123 更新时间:2023-12-01 11:37:14 24 4
gpt4 key购买 nike

我们正在尝试将拒绝服务攻击作为互联网安全项目来执行,因此我们设置了客户端和服务器。客户端执行以下操作

private void pingAttack() throws Exception {
String url = "127.0.0.1";
InetAddress inet = InetAddress.getByName(url);
for(int counter = 0; counter < 1000000000; counter++) {
System.out.println(inet.isReachable(5000) ? "available" : "NA");
}
}

在服务器中,我需要对此进行对策,因此我需要检测发送的 ping,并在特定数量的 ping 后断开与用户的连接,但我不知道如何执行此操作。我们应该在服务器端的doGet()方法中写什么?

最佳答案

isReachable 不会产生 HTTP 请求,因此您的 doGet、doXXX 方法永远不会被调用。

来自 InetAddress 的 Javadocs

Test whether that address is reachable. Best effort is made by the implementation to try to reach the host, but firewalls and server configuration may block requests resulting in a unreachable status while some specific ports may be accessible. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host.

但是,如果您尝试阻止 HTTP 请求的 DoS,可以将容器(Tomcat、Jetty 等)配置为仅接受最大数量的并发请求,之后将忽略更多请求。

关于java - 如何检测 Servlet 内的 ping?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29852527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com