Commit 8e3c56ee4ebfbda5551ce3d32e50c3a4f571814d
1 parent
965b4941
添加ip
Showing
28 changed files
with
443 additions
and
36 deletions
Too many changes to show.
To preserve performance only 28 of 30 files are displayed.
src/main/java/com/canrd/webmagic/config/MybatisPlusConfig.java
1 | package com.canrd.webmagic.config; | 1 | package com.canrd.webmagic.config; |
2 | 2 | ||
3 | +import com.baomidou.mybatisplus.annotation.DbType; | ||
4 | +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | ||
5 | +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | ||
6 | +import org.mybatis.spring.annotation.MapperScan; | ||
7 | +import org.springframework.context.annotation.Bean; | ||
3 | import org.springframework.context.annotation.Configuration; | 8 | import org.springframework.context.annotation.Configuration; |
9 | +import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
4 | 10 | ||
5 | - | 11 | +@EnableTransactionManagement |
6 | @Configuration | 12 | @Configuration |
13 | +@MapperScan("com.canrd.webmagic.mapper") | ||
7 | public class MybatisPlusConfig { | 14 | public class MybatisPlusConfig { |
8 | - | ||
9 | -} | 15 | + /** |
16 | + * | ||
17 | + * @return | ||
18 | + */ | ||
19 | + @Bean | ||
20 | + public MybatisPlusInterceptor addPaginationInnerInterceptor(){ | ||
21 | + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); | ||
22 | + PaginationInnerInterceptor innerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL); | ||
23 | + interceptor.addInnerInterceptor(innerInterceptor); | ||
24 | + return interceptor; | ||
25 | + } | ||
26 | +} | ||
10 | \ No newline at end of file | 27 | \ No newline at end of file |
src/main/java/com/canrd/webmagic/config/MybatisplusObjectMetaHandler.java
1 | -package com.gec.tra.system.config; | ||
2 | - | ||
3 | -import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; | ||
4 | -import org.apache.ibatis.reflection.MetaObject; | ||
5 | -import org.springframework.stereotype.Component; | ||
6 | - | ||
7 | -import java.util.Date; | ||
8 | - | ||
9 | - | ||
10 | -// 做自动填充 工具类 | ||
11 | -// mp 讲过 大家可以翻之前视频 | ||
12 | -@Component | ||
13 | -public class MybatisplusObjectMetaHandler implements MetaObjectHandler { | ||
14 | - | ||
15 | - | ||
16 | - // mp 在执行添加的时候,这个方法会被执行 | ||
17 | - @Override | ||
18 | - public void insertFill(MetaObject metaObject) { | ||
19 | - | ||
20 | - this.setFieldValByName("createDate",new Date(),metaObject); | ||
21 | - | ||
22 | - } | ||
23 | - | ||
24 | - // mp 在执行修改的时候,这个方法会执行 | ||
25 | - @Override | ||
26 | - public void updateFill(MetaObject metaObject) { | ||
27 | - this.setFieldValByName("updateDate",new Date(),metaObject); | ||
28 | - | ||
29 | - } | ||
30 | -} | ||
31 | \ No newline at end of file | 1 | \ No newline at end of file |
2 | +//package com.canrd.webmagic.config; | ||
3 | +// | ||
4 | +//import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; | ||
5 | +//import org.apache.ibatis.reflection.MetaObject; | ||
6 | +//import org.springframework.stereotype.Component; | ||
7 | +// | ||
8 | +//import java.util.Date; | ||
9 | +// | ||
10 | +// | ||
11 | +//@Component | ||
12 | +//public class MybatisplusObjectMetaHandler implements MetaObjectHandler { | ||
13 | +// @Override | ||
14 | +// public void insertFill(MetaObject metaObject) { | ||
15 | +// this.setFieldValByName("createDate",new Date(),metaObject); | ||
16 | +// } | ||
17 | +// | ||
18 | +// @Override | ||
19 | +// public void updateFill(MetaObject metaObject) { | ||
20 | +// this.setFieldValByName("updateDate",new Date(),metaObject); | ||
21 | +// } | ||
22 | +//} | ||
32 | \ No newline at end of file | 23 | \ No newline at end of file |
src/main/java/com/canrd/webmagic/controller/IPUqiDataController.java
0 → 100644
1 | +package com.canrd.webmagic.controller; | ||
2 | + | ||
3 | +import com.canrd.webmagic.common.constant.ServerResult; | ||
4 | +import com.canrd.webmagic.processor.IPUqiDataProcessor; | ||
5 | +import com.canrd.webmagic.processor.ScienginePcoessor; | ||
6 | +import com.canrd.webmagic.processor.download.SeleniumDownloader; | ||
7 | +import com.canrd.webmagic.processor.pipeline.ArticlePipeline; | ||
8 | +import io.swagger.annotations.Api; | ||
9 | +import io.swagger.annotations.ApiOperation; | ||
10 | +import org.apache.logging.log4j.core.util.UuidUtil; | ||
11 | +import org.springframework.web.bind.annotation.GetMapping; | ||
12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
13 | +import org.springframework.web.bind.annotation.RestController; | ||
14 | +import us.codecraft.webmagic.Request; | ||
15 | +import us.codecraft.webmagic.Spider; | ||
16 | + | ||
17 | +import javax.annotation.Resource; | ||
18 | +@RestController | ||
19 | +@RequestMapping("/uqidata/ip") | ||
20 | +@Api("IP-Uqidata") | ||
21 | +public class IPUqiDataController { | ||
22 | + @Resource | ||
23 | + private IPUqiDataProcessor ipUqiDataProcessor; | ||
24 | + | ||
25 | + @Resource | ||
26 | + private SeleniumDownloader seleniumDownloader; | ||
27 | + | ||
28 | + | ||
29 | + @GetMapping("/start") | ||
30 | + @ApiOperation("start") | ||
31 | + public ServerResult start() { | ||
32 | + Spider.create(ipUqiDataProcessor) | ||
33 | + .setUUID(UuidUtil.getTimeBasedUuid().toString()) | ||
34 | + .addRequest(new Request("https://ip.uqidata.com/freeip-0.html")) | ||
35 | + .setDownloader(seleniumDownloader) | ||
36 | + .thread(1).run(); | ||
37 | + return ServerResult.success(); | ||
38 | + } | ||
39 | +} |
src/main/java/com/canrd/webmagic/controller/IpCheckController.java
0 → 100644
1 | +package com.canrd.webmagic.controller; | ||
2 | + | ||
3 | +import com.canrd.webmagic.common.constant.ServerResult; | ||
4 | +import com.canrd.webmagic.domain.dto.IpDO; | ||
5 | +import com.canrd.webmagic.service.IpService; | ||
6 | +import com.canrd.webmagic.util.PingUtil; | ||
7 | +import io.swagger.annotations.Api; | ||
8 | +import org.springframework.web.bind.annotation.GetMapping; | ||
9 | +import org.springframework.web.bind.annotation.PathVariable; | ||
10 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
11 | +import org.springframework.web.bind.annotation.RestController; | ||
12 | + | ||
13 | +import javax.annotation.Resource; | ||
14 | +import java.util.Date; | ||
15 | +import java.util.List; | ||
16 | +import java.util.concurrent.atomic.AtomicInteger; | ||
17 | + | ||
18 | +@RestController | ||
19 | +@RequestMapping("/ip") | ||
20 | +@Api("Ip-Check") | ||
21 | +public class IpCheckController { | ||
22 | + @Resource | ||
23 | + private IpService ipService; | ||
24 | + | ||
25 | + @GetMapping("/getIpById/{id}") | ||
26 | + public ServerResult getIpById(@PathVariable int id){ | ||
27 | + IpDO ip = ipService.getById(id); | ||
28 | + return ServerResult.success(ip); | ||
29 | + } | ||
30 | + | ||
31 | + @GetMapping("/getIps") | ||
32 | + public ServerResult getIps(){ | ||
33 | + List<IpDO> ipList = ipService.findAll(); | ||
34 | + return ServerResult.success(ipList); | ||
35 | + } | ||
36 | + | ||
37 | + @GetMapping("/checkIps") | ||
38 | + public ServerResult checkIps(){ | ||
39 | + List<IpDO> ipList = ipService.findAll(); | ||
40 | + AtomicInteger error= new AtomicInteger(); | ||
41 | + AtomicInteger success= new AtomicInteger(); | ||
42 | + ipList.forEach(ip-> { | ||
43 | + if (!PingUtil.ping(ip.getIp(),4,3000)) { | ||
44 | + ip.setIsUse(1); | ||
45 | + ip.setDetectionTime(new Date()); | ||
46 | + ipService.updateById(ip); | ||
47 | + error.addAndGet(1); | ||
48 | + }else { | ||
49 | + success.addAndGet(1); | ||
50 | + } | ||
51 | + }); | ||
52 | + String mes ="本次检测,存活ip数为"+success+",失活ip数为"+error; | ||
53 | + return ServerResult.success(mes); | ||
54 | + } | ||
55 | + | ||
56 | + @GetMapping("/randomIp") | ||
57 | + public ServerResult randomIp(){ | ||
58 | + List<IpDO> ip = ipService.findAll(); | ||
59 | + int size = ip.size(); | ||
60 | + int ran = (int) (Math.random() * size-1); | ||
61 | + IpDO ipDO = ip.get(ran); | ||
62 | + return ServerResult.success(ipDO); | ||
63 | + } | ||
64 | +} |
src/main/java/com/canrd/webmagic/controller/SciengineController.java
@@ -35,7 +35,7 @@ public class SciengineController { | @@ -35,7 +35,7 @@ public class SciengineController { | ||
35 | .setUUID(UuidUtil.getTimeBasedUuid().toString()) | 35 | .setUUID(UuidUtil.getTimeBasedUuid().toString()) |
36 | .addRequest(new Request("https://www.sciengine.com/plat/search?queryField_a=battery")) | 36 | .addRequest(new Request("https://www.sciengine.com/plat/search?queryField_a=battery")) |
37 | .addPipeline(articlePipeline) | 37 | .addPipeline(articlePipeline) |
38 | - .thread(20).run(); | 38 | + .thread(60).run(); |
39 | return ServerResult.success(); | 39 | return ServerResult.success(); |
40 | } | 40 | } |
41 | } | 41 | } |
src/main/java/com/canrd/webmagic/domain/dto/IpDO.java
0 → 100644
1 | +package com.canrd.webmagic.domain.dto; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
4 | +import lombok.*; | ||
5 | +import lombok.experimental.SuperBuilder; | ||
6 | + | ||
7 | +import java.util.Date; | ||
8 | + | ||
9 | +@TableName("ip") | ||
10 | +@Data | ||
11 | +public class IpDO{ | ||
12 | + private int id; | ||
13 | + private String ip; | ||
14 | + private int port; | ||
15 | + private String type; | ||
16 | + private String anonymity; | ||
17 | + private String region; | ||
18 | + private String speed; | ||
19 | + private Date detectionTime; | ||
20 | + private int isUse; | ||
21 | +} |
src/main/java/com/canrd/webmagic/mapper/IpMapper.java
0 → 100644
src/main/java/com/canrd/webmagic/processor/IPUqiDataProcessor.java
0 → 100644
1 | +package com.canrd.webmagic.processor; | ||
2 | + | ||
3 | +import com.canrd.webmagic.domain.dto.IpDO; | ||
4 | +import lombok.extern.slf4j.Slf4j; | ||
5 | +import org.springframework.stereotype.Component; | ||
6 | +import us.codecraft.webmagic.Page; | ||
7 | +import us.codecraft.webmagic.Request; | ||
8 | +import us.codecraft.webmagic.Site; | ||
9 | +import us.codecraft.webmagic.processor.PageProcessor; | ||
10 | +import us.codecraft.webmagic.selector.Html; | ||
11 | +import us.codecraft.webmagic.selector.Selectable; | ||
12 | + | ||
13 | +import java.util.ArrayList; | ||
14 | +import java.util.Arrays; | ||
15 | +import java.util.Collection; | ||
16 | +import java.util.List; | ||
17 | + | ||
18 | +@Component | ||
19 | +@Slf4j | ||
20 | +public class IPUqiDataProcessor implements PageProcessor { | ||
21 | + private static int index = 0; | ||
22 | + | ||
23 | + @Override | ||
24 | + public void process(Page page) { | ||
25 | + String url = page.getUrl().get(); | ||
26 | + if (url.contains("https://ip.uqidata.com/freeip-") && index == 0) { | ||
27 | + getMaxPage(page); | ||
28 | + } else if (url.contains("https://ip.uqidata.com/freeip-") && index == 1) { | ||
29 | + everyPage(page); | ||
30 | + } else if (url.contains("https://ip.uqidata.com/freeip/")) { | ||
31 | + getPageDetail(page); | ||
32 | + } | ||
33 | + } | ||
34 | + | ||
35 | + @Override | ||
36 | + public Site getSite() { | ||
37 | + return PageProcessor.super.getSite(); | ||
38 | + } | ||
39 | + | ||
40 | + void getMaxPage(Page page) { | ||
41 | + index = 1; | ||
42 | + Html html = page.getHtml(); | ||
43 | + List<String> pageList = html.xpath("//div[@class='wp-pagenavi pd25']/a/text()").all(); | ||
44 | + for (int i = 1; i <= Integer.parseInt(pageList.get(pageList.size() - 1)); i++) { | ||
45 | + page.addTargetRequest("https://ip.uqidata.com/freeip-" + i + ".html"); | ||
46 | + } | ||
47 | + } | ||
48 | + | ||
49 | + void everyPage(Page page) { | ||
50 | + Html html = page.getHtml(); | ||
51 | + log.info(page.getUrl().get()); | ||
52 | + List<String> hrefList = html.xpath("//div[@class='entry entry-content freeip']/h2/a/@href").all(); | ||
53 | + hrefList.forEach(href->page.addTargetRequest("https:"+href)); | ||
54 | + } | ||
55 | + | ||
56 | + void getPageDetail(Page page) { | ||
57 | + Html html = page.getHtml(); | ||
58 | + String ips = html.xpath("//div[@class='content']/p[@class!='pd25']/text()").get(); | ||
59 | + String[] ipArray = ips.split(" "); | ||
60 | + List ipDoList = new ArrayList<>(); | ||
61 | + for (int i = 0; i < ipArray.length; i += 3) { | ||
62 | + IpDO ipDO = new IpDO(); | ||
63 | + String[] ip_port = ipArray[i].split(":"); | ||
64 | + String ip = ip_port[0]; | ||
65 | + int port = Integer.parseInt(ip_port[1]); | ||
66 | + String anonymity = ipArray[i+1]; | ||
67 | + StringBuffer region = new StringBuffer(); | ||
68 | + char[] chars = ipArray[i + 2].toCharArray(); | ||
69 | + for (int j = 0; j < chars.length; j++) { | ||
70 | + if (!Character.isDigit(chars[j])){ | ||
71 | + region.append(chars[j]); | ||
72 | + } | ||
73 | + } | ||
74 | + ipDO.setIp(ip); | ||
75 | + ipDO.setPort(port); | ||
76 | + ipDO.setAnonymity(anonymity); | ||
77 | + ipDO.setRegion(String.valueOf(region)); | ||
78 | + ipDoList.add(ipDO); | ||
79 | + } | ||
80 | + page.putField("ips",ipDoList); | ||
81 | + } | ||
82 | +} |
src/main/java/com/canrd/webmagic/processor/download/SeleniumDownloader.java
@@ -29,7 +29,7 @@ import java.util.regex.Pattern; | @@ -29,7 +29,7 @@ import java.util.regex.Pattern; | ||
29 | @Slf4j | 29 | @Slf4j |
30 | @Component | 30 | @Component |
31 | public class SeleniumDownloader extends AbstractDownloader { | 31 | public class SeleniumDownloader extends AbstractDownloader { |
32 | - private int sleepTime = 3000000; | 32 | + private int sleepTime = 10000; |
33 | 33 | ||
34 | @Resource | 34 | @Resource |
35 | private SeleniumConfig config; | 35 | private SeleniumConfig config; |
@@ -98,7 +98,7 @@ public class SeleniumDownloader extends AbstractDownloader { | @@ -98,7 +98,7 @@ public class SeleniumDownloader extends AbstractDownloader { | ||
98 | String pageSource = webDriver.getPageSource(); | 98 | String pageSource = webDriver.getPageSource(); |
99 | log.info(pageSource); | 99 | log.info(pageSource); |
100 | // WebElement element = webDriver.findElement(By.xpath("//div[@class='form-row']/from/div[@id='jsEnabled']/input")); | 100 | // WebElement element = webDriver.findElement(By.xpath("//div[@class='form-row']/from/div[@id='jsEnabled']/input")); |
101 | - webDriver.findElement(By.xpath("//a[@class='ot-sdk-show-settings cookie anchor-text']")).click(); | 101 | +// webDriver.findElement(By.xpath("//a[@class='ot-sdk-show-settings cookie anchor-text']")).click(); |
102 | webDriver.findElement(By.xpath("//input[@id='bdd-email']")).getAttribute("1187551704@qq.com"); | 102 | webDriver.findElement(By.xpath("//input[@id='bdd-email']")).getAttribute("1187551704@qq.com"); |
103 | webDriver.findElement(By.xpath("//button[@id='bdd-els-searchBtn']")).submit(); | 103 | webDriver.findElement(By.xpath("//button[@id='bdd-els-searchBtn']")).submit(); |
104 | // String text = element.getText(); | 104 | // String text = element.getText(); |
@@ -137,6 +137,7 @@ public class SeleniumDownloader extends AbstractDownloader { | @@ -137,6 +137,7 @@ public class SeleniumDownloader extends AbstractDownloader { | ||
137 | page.setHtml(new Html(content, request.getUrl())); | 137 | page.setHtml(new Html(content, request.getUrl())); |
138 | page.setUrl(new PlainText(request.getUrl())); | 138 | page.setUrl(new PlainText(request.getUrl())); |
139 | page.setRequest(request); | 139 | page.setRequest(request); |
140 | + log.info("onSuccess"); | ||
140 | onSuccess(request, task); | 141 | onSuccess(request, task); |
141 | } catch (Exception e) { | 142 | } catch (Exception e) { |
142 | log.warn("download page {} error", request.getUrl(), e); | 143 | log.warn("download page {} error", request.getUrl(), e); |
src/main/java/com/canrd/webmagic/processor/pipeline/IpPipeline.java
0 → 100644
1 | +package com.canrd.webmagic.processor.pipeline; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
5 | +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | ||
6 | +import com.canrd.webmagic.domain.dto.ArticleDO; | ||
7 | +import com.canrd.webmagic.domain.dto.IpDO; | ||
8 | +import com.canrd.webmagic.service.IpService; | ||
9 | +import us.codecraft.webmagic.ResultItems; | ||
10 | +import us.codecraft.webmagic.Task; | ||
11 | +import us.codecraft.webmagic.pipeline.Pipeline; | ||
12 | + | ||
13 | +import javax.annotation.Resource; | ||
14 | +import java.util.List; | ||
15 | +import java.util.Objects; | ||
16 | + | ||
17 | +public class IpPipeline implements Pipeline { | ||
18 | + @Resource | ||
19 | + private IpService ipService; | ||
20 | + | ||
21 | + @Override | ||
22 | + public void process(ResultItems resultItems, Task task) { | ||
23 | + List<IpDO> ips= resultItems.get("ips"); | ||
24 | + if (CollectionUtils.isNotEmpty(ips)) { | ||
25 | + for (IpDO ipDO : ips) { | ||
26 | + QueryWrapper<IpDO> ipDOQueryWrapper = new QueryWrapper<IpDO>() | ||
27 | + .eq("ip",ipDO.getIp()) | ||
28 | + .eq("port",ipDO.getPort()) | ||
29 | + .eq("anonymity",ipDO.getAnonymity()) | ||
30 | + .eq("region",ipDO.getRegion()); | ||
31 | + List<IpDO> ipList = ipService.list(ipDOQueryWrapper); | ||
32 | + if (CollectionUtils.isNotEmpty(ipList)) { | ||
33 | + return; | ||
34 | + } | ||
35 | + ipService.save(ipDO); | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | +} |
src/main/java/com/canrd/webmagic/service/IpService.java
0 → 100644
1 | +package com.canrd.webmagic.service; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import com.baomidou.mybatisplus.extension.service.IService; | ||
5 | +import com.canrd.webmagic.domain.dto.IpDO; | ||
6 | +import com.canrd.webmagic.mapper.IpMapper; | ||
7 | + | ||
8 | +import java.util.List; | ||
9 | + | ||
10 | +public interface IpService extends IService<IpDO> { | ||
11 | + | ||
12 | + List<IpDO> findAll(); | ||
13 | +} |
src/main/java/com/canrd/webmagic/service/impl/IpServiceImpl.java
0 → 100644
1 | +package com.canrd.webmagic.service.impl; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
4 | +import com.canrd.webmagic.domain.dto.IpDO; | ||
5 | +import com.canrd.webmagic.mapper.IpMapper; | ||
6 | +import com.canrd.webmagic.service.IpService; | ||
7 | +import org.springframework.stereotype.Service; | ||
8 | + | ||
9 | +import java.util.List; | ||
10 | + | ||
11 | +@Service | ||
12 | +public class IpServiceImpl extends ServiceImpl<IpMapper,IpDO> implements IpService { | ||
13 | + | ||
14 | + @Override | ||
15 | + public List<IpDO> findAll() { | ||
16 | + return this.baseMapper.findAll(); | ||
17 | + } | ||
18 | +} |
src/main/java/com/canrd/webmagic/util/PingUtil.java
0 → 100644
1 | +package com.canrd.webmagic.util; | ||
2 | + | ||
3 | +import java.io.BufferedReader; | ||
4 | +import java.io.IOException; | ||
5 | +import java.io.InputStreamReader; | ||
6 | +import java.net.InetAddress; | ||
7 | +import java.util.regex.Matcher; | ||
8 | +import java.util.regex.Pattern; | ||
9 | + | ||
10 | +public class PingUtil { | ||
11 | + | ||
12 | + public static boolean ping(String ipAddress) throws Exception { | ||
13 | + int timeOut = 3000 ; | ||
14 | + boolean status = InetAddress.getByName(ipAddress).isReachable(timeOut); | ||
15 | + return status; | ||
16 | + } | ||
17 | + | ||
18 | + public static void ping02(String ipAddress) throws Exception { | ||
19 | + String line = null; | ||
20 | + try { | ||
21 | + Process pro = Runtime.getRuntime().exec("ping " + ipAddress); | ||
22 | + BufferedReader buf = new BufferedReader(new InputStreamReader( | ||
23 | + pro.getInputStream())); | ||
24 | + while ((line = buf.readLine()) != null) | ||
25 | + System.out.println(line); | ||
26 | + } catch (Exception ex) { | ||
27 | + System.out.println(ex.getMessage()); | ||
28 | + } | ||
29 | + } | ||
30 | + | ||
31 | + public static boolean ping(String ipAddress, int pingTimes, int timeOut) { | ||
32 | + BufferedReader in = null; | ||
33 | + Runtime r = Runtime.getRuntime(); // 将要执行的ping命令,此命令是windows格式的命令 | ||
34 | + String pingCommand = "ping " + ipAddress + " -n " + pingTimes + " -w " + timeOut; | ||
35 | + try { // 执行命令并获取输出 | ||
36 | + System.out.println(pingCommand); | ||
37 | + Process p = r.exec(pingCommand); | ||
38 | + if (p == null) { | ||
39 | + return false; | ||
40 | + } | ||
41 | + in = new BufferedReader(new InputStreamReader(p.getInputStream())); // 逐行检查输出,计算类似出现=23ms TTL=62字样的次数 | ||
42 | + int connectedCount = 0; | ||
43 | + String line = null; | ||
44 | + while ((line = in.readLine()) != null) { | ||
45 | + connectedCount += getCheckResult(line); | ||
46 | + } // 如果出现类似=23ms TTL=62这样的字样,出现的次数=测试次数则返回真 | ||
47 | + return connectedCount == pingTimes; | ||
48 | + } catch (Exception ex) { | ||
49 | + ex.printStackTrace(); // 出现异常则返回假 | ||
50 | + return false; | ||
51 | + } finally { | ||
52 | + try { | ||
53 | + in.close(); | ||
54 | + } catch (IOException e) { | ||
55 | + e.printStackTrace(); | ||
56 | + } | ||
57 | + } | ||
58 | + } | ||
59 | + //若line含有=18ms TTL=16字样,说明已经ping通,返回1,否則返回0. | ||
60 | + private static int getCheckResult(String line) { // System.out.println("控制台输出的结果为:"+line); | ||
61 | + Pattern pattern = Pattern.compile("(\\d+ms)(\\s+)(TTL=\\d+)",Pattern.CASE_INSENSITIVE); | ||
62 | + Matcher matcher = pattern.matcher(line); | ||
63 | + while (matcher.find()) { | ||
64 | + return 1; | ||
65 | + } | ||
66 | + return 0; | ||
67 | + } | ||
68 | + public static void main(String[] args) throws Exception { | ||
69 | + String ipAddress = "127.0.0.1"; | ||
70 | + System.out.println(ping(ipAddress)); | ||
71 | + ping02(ipAddress); | ||
72 | + System.out.println(ping(ipAddress, 5, 5000)); | ||
73 | + } | ||
74 | +} | ||
0 | \ No newline at end of file | 75 | \ No newline at end of file |
src/main/resources/Mapper/IpMapper.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | +<mapper namespace="com.canrd.webmagic.mapper.IpMapper"> | ||
4 | + | ||
5 | + <resultMap id="IpMap" type="com.canrd.webmagic.domain.dto.IpDO"> | ||
6 | + </resultMap> | ||
7 | + | ||
8 | + <sql id="columns"> | ||
9 | + id,ip,port,type,anonymity,region,speed,detection_time,is_use | ||
10 | + </sql> | ||
11 | + <select id="findAll" resultMap="IpMap"> | ||
12 | + select <include refid="columns"></include> | ||
13 | + from ip | ||
14 | + <where> | ||
15 | + is_use = 0 | ||
16 | + </where> | ||
17 | + </select> | ||
18 | + | ||
19 | +</mapper> | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
target/classes/Mapper/IpMapper.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | +<mapper namespace="com.canrd.webmagic.mapper.IpMapper"> | ||
4 | + | ||
5 | + <resultMap id="IpMap" type="com.canrd.webmagic.domain.dto.IpDO"> | ||
6 | + </resultMap> | ||
7 | + | ||
8 | + <sql id="columns"> | ||
9 | + id,ip,port,type,anonymity,region,speed,detection_time,is_use | ||
10 | + </sql> | ||
11 | + <select id="findAll" resultMap="IpMap"> | ||
12 | + select <include refid="columns"></include> | ||
13 | + from ip | ||
14 | + <where> | ||
15 | + is_use = 0 | ||
16 | + </where> | ||
17 | + </select> | ||
18 | + | ||
19 | +</mapper> | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
target/classes/com/canrd/webmagic/config/MybatisPlusConfig.class
No preview for this file type
target/classes/com/canrd/webmagic/controller/IPUqiDataController.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/controller/IpCheckController.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/controller/SciengineController.class
No preview for this file type
target/classes/com/canrd/webmagic/domain/dto/IpDO.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/mapper/IpMapper.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/processor/IPUqiDataProcessor.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/processor/download/SeleniumDownloader.class
No preview for this file type
target/classes/com/canrd/webmagic/processor/pipeline/IpPipeline.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/service/IpService.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/service/impl/IpServiceImpl.class
0 → 100644
No preview for this file type
target/classes/com/canrd/webmagic/util/PingUtil.class
0 → 100644
No preview for this file type
target/classes/com/gec/tra/system/config/MybatisplusObjectMetaHandler.class deleted
100644 → 0
No preview for this file type