mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 08:59:10 +08:00
copyright
This commit is contained in:
parent
8976e9dbd8
commit
4537ac630c
2
LICENSE
2
LICENSE
@ -187,7 +187,7 @@
|
|||||||
same "printed page" as the copyright notice for easier
|
same "printed page" as the copyright notice for easier
|
||||||
identification within third-party archives.
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -33,7 +33,6 @@ import org.maxkey.persistence.service.UserInfoService;
|
|||||||
import org.maxkey.util.DateUtils;
|
import org.maxkey.util.DateUtils;
|
||||||
import org.maxkey.web.WebConstants;
|
import org.maxkey.web.WebConstants;
|
||||||
import org.maxkey.web.WebContext;
|
import org.maxkey.web.WebContext;
|
||||||
import org.maxkey.web.ipregion.IpRegionFactory;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
@ -139,9 +138,6 @@ public abstract class AbstractAuthenticationRealm {
|
|||||||
historyLogin.setBrowser(browser.getName());
|
historyLogin.setBrowser(browser.getName());
|
||||||
historyLogin.setPlatform(browser.getPlatform());
|
historyLogin.setPlatform(browser.getPlatform());
|
||||||
historyLogin.setSourceIp(userInfo.getLastLoginIp());
|
historyLogin.setSourceIp(userInfo.getLastLoginIp());
|
||||||
//TODO:
|
|
||||||
//historyLogin.setIpRegion(IpRegionFactory.getFactory().region(userInfo.getLastLoginIp()));
|
|
||||||
//historyLogin.setIpLocation(IpRegionFactory.getFactory().getLocation(historyLogin.getIpRegion()));
|
|
||||||
historyLogin.setProvider(provider);
|
historyLogin.setProvider(provider);
|
||||||
historyLogin.setCode(code);
|
historyLogin.setCode(code);
|
||||||
historyLogin.setLoginType(type);
|
historyLogin.setLoginType(type);
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
public abstract class AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
int failCount = 0;
|
|
||||||
|
|
||||||
public String getLocation(String region) {
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFailCount() {
|
|
||||||
return failCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
public int plusFailCount() {
|
|
||||||
return failCount++;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
public interface IpRegion {
|
|
||||||
public static final String USERAGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36";
|
|
||||||
|
|
||||||
public static final int TIMEOUT = 5000;
|
|
||||||
|
|
||||||
public String region(String ipAddress);
|
|
||||||
|
|
||||||
public String getLocation(String region);
|
|
||||||
|
|
||||||
public int getFailCount();
|
|
||||||
|
|
||||||
public int plusFailCount() ;
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
public class IpRegionFactory extends AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
static IpRegionFactory factory = new IpRegionFactory();
|
|
||||||
|
|
||||||
static final ArrayList<IpRegion> ipRegionList;
|
|
||||||
|
|
||||||
static {
|
|
||||||
ipRegionList = new ArrayList<IpRegion>();
|
|
||||||
ipRegionList.add(new IpRegionLocal());
|
|
||||||
ipRegionList.add(new IpRegionIp138());
|
|
||||||
ipRegionList.add(new IpRegionIpchaxun());
|
|
||||||
ipRegionList.add(new IpRegionIpcn());
|
|
||||||
ipRegionList.add(new IpRegionIp360());
|
|
||||||
ipRegionList.add(new IpRegionPconline());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IpRegion getFactory() {
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String region(String ipAddress) {
|
|
||||||
for(int i = 0 ; i<ipRegionList.size() ; i++ ) {
|
|
||||||
IpRegion ipRegion = ipRegionList.get(i);
|
|
||||||
String region = ipRegion.region(ipAddress);
|
|
||||||
if(StringUtils.isNotBlank(region)) {
|
|
||||||
return region;
|
|
||||||
}else {
|
|
||||||
if(ipRegion.getFailCount() > 6) {
|
|
||||||
ipRegionList.remove(i);//remove from list
|
|
||||||
}
|
|
||||||
//fail plus 1
|
|
||||||
ipRegion.plusFailCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocation(String region) {
|
|
||||||
if(region.endsWith("电信") || region.endsWith("移动") || region.endsWith("联通")) {
|
|
||||||
region.substring(0, region.length() - 2).trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(region.indexOf(" ") > 0) {
|
|
||||||
return region.split(" ")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
import org.maxkey.util.JsonUtils;
|
|
||||||
|
|
||||||
public class IpRegionIp138 extends AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
public static final String REGION_URL = "https://www.ip138.com/iplookup.asp?ip=%s&action=2";
|
|
||||||
|
|
||||||
public static final String BEGIN = "\"ip_c_list\":[";
|
|
||||||
public static final String END = "], \"zg\":1};";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String region(String ipAddress) {
|
|
||||||
try {
|
|
||||||
Document doc;
|
|
||||||
doc = Jsoup.connect(String.format(REGION_URL, ipAddress))
|
|
||||||
.timeout(TIMEOUT)
|
|
||||||
.userAgent(USERAGENT)
|
|
||||||
.header("Host", "www.ip138.com")
|
|
||||||
.header("Referer", "https://www.ip138.com/")
|
|
||||||
.header("sec-ch-ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\"")
|
|
||||||
.header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
|
|
||||||
.get();
|
|
||||||
String htmlData = doc.toString();
|
|
||||||
String jsonData = htmlData.substring(htmlData.indexOf(BEGIN) + BEGIN.length() , htmlData.indexOf(END));
|
|
||||||
IpRegionIp138Response responseJson = JsonUtils.json2Object(jsonData, IpRegionIp138Response.class);
|
|
||||||
return responseJson == null ? null : responseJson.toString();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class IpRegionIp138Response {
|
|
||||||
|
|
||||||
String ct;
|
|
||||||
String prov;
|
|
||||||
String city;
|
|
||||||
String area;
|
|
||||||
String yunyin;
|
|
||||||
|
|
||||||
public IpRegionIp138Response() {
|
|
||||||
}
|
|
||||||
public String getCt() {
|
|
||||||
return ct;
|
|
||||||
}
|
|
||||||
public void setCt(String ct) {
|
|
||||||
this.ct = ct;
|
|
||||||
}
|
|
||||||
public String getProv() {
|
|
||||||
return prov;
|
|
||||||
}
|
|
||||||
public void setProv(String prov) {
|
|
||||||
this.prov = prov;
|
|
||||||
}
|
|
||||||
public String getCity() {
|
|
||||||
return city;
|
|
||||||
}
|
|
||||||
public void setCity(String city) {
|
|
||||||
this.city = city;
|
|
||||||
}
|
|
||||||
public String getArea() {
|
|
||||||
return area;
|
|
||||||
}
|
|
||||||
public void setArea(String area) {
|
|
||||||
this.area = area;
|
|
||||||
}
|
|
||||||
public String getYunyin() {
|
|
||||||
return yunyin;
|
|
||||||
}
|
|
||||||
public void setYunyin(String yunyin) {
|
|
||||||
this.yunyin = yunyin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append(ct)
|
|
||||||
.append(prov)
|
|
||||||
.append(city)
|
|
||||||
.append(area)
|
|
||||||
.append(" ")
|
|
||||||
.append(yunyin);
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
import org.maxkey.util.JsonUtils;
|
|
||||||
|
|
||||||
public class IpRegionIp360 extends AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
public static final String REGION_URL = "http://ip.360.cn/IPQuery/ipquery?ip=%s&verifycode=";
|
|
||||||
public static final String BEGIN = "<body>";
|
|
||||||
public static final String END = "</body>";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String region(String ipAddress) {
|
|
||||||
try {
|
|
||||||
Document doc;
|
|
||||||
doc = Jsoup.connect(String.format(REGION_URL, ipAddress))
|
|
||||||
.timeout(TIMEOUT)
|
|
||||||
.userAgent(USERAGENT)
|
|
||||||
.header("Host", "ip.360.cn")
|
|
||||||
.header("Origin", "http://ip.360.cn")
|
|
||||||
.header("Referer", "http://ip.360.cn/")
|
|
||||||
.header("Accept","application/json, text/plain, */*")
|
|
||||||
.post();
|
|
||||||
|
|
||||||
String htmlData = doc.toString();
|
|
||||||
String jsonData = htmlData.substring(htmlData.indexOf(BEGIN) + BEGIN.length() , htmlData.indexOf(END));
|
|
||||||
IpRegionIp360Response responseJson = JsonUtils.json2Object(jsonData, IpRegionIp360Response.class);
|
|
||||||
return responseJson == null ? null : responseJson.getData().replace("\t", " ");
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
public class IpRegionIp360Response {
|
|
||||||
|
|
||||||
int errno;
|
|
||||||
String errmsg;
|
|
||||||
String data;
|
|
||||||
public int getErrno() {
|
|
||||||
return errno;
|
|
||||||
}
|
|
||||||
public void setErrno(int errno) {
|
|
||||||
this.errno = errno;
|
|
||||||
}
|
|
||||||
public String getErrmsg() {
|
|
||||||
return errmsg;
|
|
||||||
}
|
|
||||||
public void setErrmsg(String errmsg) {
|
|
||||||
this.errmsg = errmsg;
|
|
||||||
}
|
|
||||||
public String getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
public void setData(String data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append("IpRegionIp360Response [errno=");
|
|
||||||
builder.append(errno);
|
|
||||||
builder.append(", errmsg=");
|
|
||||||
builder.append(errmsg);
|
|
||||||
builder.append(", data=");
|
|
||||||
builder.append(data);
|
|
||||||
builder.append("]");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
import org.jsoup.select.Elements;
|
|
||||||
|
|
||||||
public class IpRegionIpchaxun extends AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
public static final String REGION_URL = "https://ipchaxun.com/%s/";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String region(String ipAddress) {
|
|
||||||
try {
|
|
||||||
Document doc;
|
|
||||||
doc = Jsoup.connect(String.format(REGION_URL, ipAddress))
|
|
||||||
.timeout(TIMEOUT)
|
|
||||||
.userAgent(USERAGENT)
|
|
||||||
.header("Host","ipchaxun.com")
|
|
||||||
.header("Referer","https://ipchaxun.com/")
|
|
||||||
.header("sec-ch-ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\"")
|
|
||||||
.header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
|
|
||||||
.get();
|
|
||||||
|
|
||||||
Elements address = doc.select(".info label span.value");
|
|
||||||
return address.get(1).text().trim();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
import org.jsoup.select.Elements;
|
|
||||||
|
|
||||||
public class IpRegionIpcn extends AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
public static final String REGION_URL = "https://ip.cn/ip/%s.html";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String region(String ipAddress) {
|
|
||||||
try {
|
|
||||||
Document doc;
|
|
||||||
doc = Jsoup.connect(String.format(REGION_URL, ipAddress))
|
|
||||||
.timeout(TIMEOUT)
|
|
||||||
.userAgent(USERAGENT)
|
|
||||||
.header("referer","https://ip.cn/")
|
|
||||||
.header("sec-ch-ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\"")
|
|
||||||
.get();
|
|
||||||
Elements address = doc.select("#tab0_address");
|
|
||||||
return address.text().trim();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
public class IpRegionLocal extends AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String region(String ipAddress) {
|
|
||||||
if(ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) {
|
|
||||||
return "local";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import org.maxkey.util.JsonUtils;
|
|
||||||
import org.maxkey.web.HttpRequestAdapter;
|
|
||||||
|
|
||||||
public class IpRegionPconline extends AbstractIpRegion implements IpRegion{
|
|
||||||
|
|
||||||
public static final String REGION_URL = "http://whois.pconline.com.cn/ipJson.jsp?json=true&ip=%s";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String region(String ipAddress) {
|
|
||||||
String responseJson =
|
|
||||||
new HttpRequestAdapter(HttpRequestAdapter.MediaType.JSON)
|
|
||||||
.get(String.format(REGION_URL,ipAddress),null);
|
|
||||||
return JsonUtils.json2Object(responseJson, IpRegionPconlineResponse.class).getAddr().trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class IpRegionPconlineResponse {
|
|
||||||
|
|
||||||
String addr;
|
|
||||||
|
|
||||||
public String getAddr() {
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddr(String addr) {
|
|
||||||
this.addr = addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IpRegionPconlineResponse() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class IpRegionFactoryTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test(){
|
|
||||||
System.out.println(IpRegionFactory.getFactory().getLocation(
|
|
||||||
IpRegionFactory.getFactory().region("127.0.0.1")
|
|
||||||
));
|
|
||||||
|
|
||||||
System.out.println(IpRegionFactory.getFactory().getLocation(
|
|
||||||
IpRegionFactory.getFactory().region("117.155.70.59")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class IpRegionIp138Test {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test(){
|
|
||||||
IpRegion ipRegion = new IpRegionIp138();
|
|
||||||
System.out.println(ipRegion.region("117.155.70.59"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class IpRegionIp360Test {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test(){
|
|
||||||
IpRegion ipRegion = new IpRegionIp360();
|
|
||||||
System.out.println(ipRegion.region("117.155.70.59"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class IpRegionIpchaxunTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test(){
|
|
||||||
IpRegion ipRegion = new IpRegionIpchaxun();
|
|
||||||
System.out.println(ipRegion.region("117.155.70.59"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class IpRegionIpcnTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test(){
|
|
||||||
IpRegion ipRegion = new IpRegionIpcn();
|
|
||||||
System.out.println(ipRegion.region("117.155.70.59"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package org.maxkey.web.ipregion;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class IpRegionPconlineTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test(){
|
|
||||||
IpRegion ipRegion = new IpRegionPconline();
|
|
||||||
System.out.println(ipRegion.region("117.155.70.59"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user