Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit e6a2685

Browse files
committed
新增whois查询
1 parent 937775d commit e6a2685

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/main/java/com/zhazhapan/modules/constant/ValueConsts.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
*
3-
*/
41
package com.zhazhapan.modules.constant;
52

63
import javax.servlet.http.HttpServletResponse;
@@ -11,6 +8,8 @@
118
*/
129
public class ValueConsts {
1310

11+
public static final String WHOIS_DOMAIN_XPATH = "//ul[@class='WhoisLeft fl']";
12+
1413
/**
1514
* 获取ip归属地的xpath
1615
*/
@@ -170,9 +169,9 @@ public class ValueConsts {
170169
* 请求头
171170
*/
172171
public static final String[] USER_AGENT = {"mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, " +
173-
"" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "like" + "" + " " + "gecko) " +
174-
"chrome/59.0.3071.115 " + "safari/537.36", "Mozilla/5.0 " + "" + "(Windows NT " + "" + "6.1; " + "" + ""
175-
+ "" + "Win64; " + "x64;" + " " + "rv:47.0)" + "" + " " + "" + "Gecko/20100101" + "" + " " +
172+
"" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "like" + "" + " " +
173+
"gecko) " + "chrome/59.0.3071.115 " + "safari/537.36", "Mozilla/5.0 " + "" + "(Windows NT " + "" + "6.1; " +
174+
"" + "" + "" + "" + "Win64; " + "x64;" + " " + "rv:47.0)" + "" + " " + "" + "Gecko/20100101" + "" + " " +
176175
"Firefox/47.0", "Mozilla/5.0 " + "" + "" + "" + "(Macintosh;" + "Intel " + "" + "Mac OS X" + " " + "" +
177176
"" + "x.y; " + "rv:42.0) " + "Gecko/20100101" + "" + " " + "Firefox/42.0", "Mozilla/5.0 " + "(X11; " +
178177
"Linux" + " " + "x86_64) " + "AppleWebKit/537.36 " + "(KHTML," + "" + " " + "like" + "" + " " + "Gecko) "
@@ -181,11 +180,11 @@ public class ValueConsts {
181180
"Gecko) " + "" + "Chrome/51.0.2704.106" + "" + "" + " " + "Safari/537.36 " + "OPR/38.0.2220.41",
182181
"Mozilla/5.0 " + "" + "" + "" + "" + "" + "" + "" + "" + "(iPhone;" + "" + " " + "CPU" + " " + "iPhone" +
183182
" " + "" + "" + "OS " + "10_3_1 " + "like" + "" + " Mac " + "" + "" + "OS " + "" + "" + "" + "X) " +
184-
"" + "" + "" + "AppleWebKit/603.1.30 " + "" + "" + "(KHTML, " + "like " + "Gecko) " +
185-
"Version/10.0" + " " + "Mobile/14E304 " + "Safari/602.1", "Mozilla/5.0" + " " + "" + "" + "" +
186-
"(compatible;" + "" + " " + "" + "MSIE " + "9.0; " + "Windows Phone " + "OS" + " 7.5;" + "" + " " +
187-
"Trident/5.0;" + "" + "" + "" + "" + "" + "" + "" + " " + "IEMobile/9.0)", "Mozilla/5.0 " + "" + "" + ""
188-
+ "(iPhone; U; CPU " + "like " + "" + "" + "Mac" + "" + " OS " + "X;" + " " + "en)" + " " +
183+
"" + "" + "" + "" + "" + "" + "AppleWebKit/603.1.30 " + "" + "" + "(KHTML, " + "like " + "Gecko) " +
184+
"" + "Version/10.0" + " " + "Mobile/14E304 " + "Safari/602.1", "Mozilla/5.0" + " " + "" + "" + ""
185+
+ "" + "(compatible;" + "" + " " + "" + "MSIE " + "9.0; " + "Windows Phone " + "OS" + " 7.5;" + "" + " "
186+
+ "Trident/5.0;" + "" + "" + "" + "" + "" + "" + "" + " " + "IEMobile/9.0)", "Mozilla/5.0 " + "" + "" +
187+
"" + "(iPhone; U; CPU " + "like " + "" + "" + "Mac" + "" + " OS " + "X;" + " " + "en)" + " " +
189188
"AppleWebKit/420+ " + "" + "" + "" + "(KHTML," + "" + " like " + "" + "Gecko) " + "Version/3.0 " + "" +
190189
"Mobile/1A543a" + " " + "Safari/419.3"};
191190

src/main/java/com/zhazhapan/util/NetUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public class NetUtils {
2525

2626
private NetUtils() {}
2727

28+
public static String whois(String domain) throws IOException, XPathExpressionException,
29+
ParserConfigurationException {
30+
String whois = evaluate(ValueConsts.WHOIS_DOMAIN_XPATH, getHtmlFromUrl("http://whois.chinaz.com/" + domain));
31+
return whois.replaceAll("\\[whois\\s?反查]", ValueConsts.EMPTY_STRING).replaceAll("\\s{2,}", "\r\n");
32+
}
33+
2834
/**
2935
* 获取ip归属地
3036
*

src/test/java/com/zhazhapan/util/NetUtilsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,21 @@ public void getInputStreamOfUrl1() {
6666
@Test
6767
public void getInputStreamOfConnection() {
6868
}
69+
70+
@Test
71+
public void whois() throws ParserConfigurationException, XPathExpressionException, IOException {
72+
System.out.println(NetUtils.whois("zhazhapan.com"));
73+
}
74+
75+
@Test
76+
public void getLocationByIp() {
77+
}
78+
79+
@Test
80+
public void getHtmlFromUrl() {
81+
}
82+
83+
@Test
84+
public void getDocumentFromUrl() {
85+
}
6986
}

0 commit comments

Comments
 (0)