ip地址信息由查询本地文件改为访问ip138
This commit is contained in:
parent
7057b28ff0
commit
c31b3ff5f0
6
pom.xml
6
pom.xml
@ -114,12 +114,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -6,10 +6,13 @@ import com.lion.lionwebsite.Domain.SubBind;
|
||||
import com.lion.lionwebsite.Domain.SubUpdateRecord;
|
||||
import com.lion.lionwebsite.Util.CustomUtil;
|
||||
import com.lion.lionwebsite.Util.FileDownload;
|
||||
import com.lion.lionwebsite.Util.GalleryUtil;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.lionsoul.ip2region.xdb.Searcher;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -18,19 +21,12 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SubService {
|
||||
SubMapper subMapper;
|
||||
|
||||
byte[] vIndex;
|
||||
|
||||
String dbPath = "ip2region.xdb";
|
||||
public SubService(SubMapper subMapper) {
|
||||
this.subMapper = subMapper;
|
||||
try {
|
||||
vIndex = Searcher.loadVectorIndexFromFile(dbPath);
|
||||
}catch (Exception e){
|
||||
System.out.printf("failed to load vector index from `%s`: %s\n", dbPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
public String insertSubBind(String user){
|
||||
@ -93,21 +89,17 @@ public class SubService {
|
||||
if(UA == null)
|
||||
return;
|
||||
|
||||
StringBuilder location = new StringBuilder();
|
||||
Searcher searcher;
|
||||
String location;
|
||||
try {
|
||||
searcher = Searcher.newWithVectorIndex(dbPath, vIndex);
|
||||
String region = searcher.search(ip);
|
||||
String[] temp = region.split("\\|");
|
||||
for (int i = 2; i < temp.length; i++)
|
||||
if(!temp[i].equals("0"))
|
||||
location.append(temp[i]).append(" ");
|
||||
} catch (Exception e) {
|
||||
System.out.printf("failed to create vectorIndex cached searcher with `%s`: %s\n", dbPath, e);
|
||||
return;
|
||||
String page = GalleryUtil.requests("https://www.ip138.com/iplookup.php?ip=" + ip, "get", null, null);
|
||||
Elements tds = Jsoup.parse(page).select("body > div > div.container > div.content > div > div:nth-child(2) > div.group-left > div > div.bd > div.table-outer > div.table-box > table > tbody > tr > td");
|
||||
location = tds.get(1).text().replace("中国", "") + " " + tds.get(3).text().trim();
|
||||
}catch (IOException e){
|
||||
log.error("获取ip地址信息失败: {}", e.getMessage());
|
||||
location = "unknown";
|
||||
}
|
||||
|
||||
SubUpdateRecord subUpdateRecord = new SubUpdateRecord(0, subBind.getUser(), ip, UA, new Date(), location.toString().trim());
|
||||
SubUpdateRecord subUpdateRecord = new SubUpdateRecord(0, subBind.getUser(), ip, UA, new Date(), location);
|
||||
subMapper.insertSubUpdateRecord(subUpdateRecord);
|
||||
if(subMapper.selectUpdateRecordCount(subBind.getUser()) > 10)
|
||||
subMapper.deleteSubUpdateRecordById(subMapper.selectMinUpdateRecordId(subBind.getUser()));
|
||||
|
||||
@ -276,8 +276,10 @@ public class GalleryUtil {
|
||||
|
||||
headers.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0");
|
||||
headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
|
||||
headers.put("Upgrade-Insecure-Requests", "1");
|
||||
headers.put("Cookie", "ipb_member_id=5774855; ipb_pass_hash=4b061c3abe25289568b5a8e0123fb3b9; igneous=cea2e08fb; sk=oye107wk02gtomb56x65dmv4qzbn; nw=1");
|
||||
if(url.contains("hentai")) {
|
||||
headers.put("Cookie", "ipb_member_id=5774855; ipb_pass_hash=4b061c3abe25289568b5a8e0123fb3b9; igneous=cea2e08fb; sk=oye107wk02gtomb56x65dmv4qzbn; nw=1");
|
||||
headers.put("Upgrade-Insecure-Requests", "1");
|
||||
}
|
||||
|
||||
if(method.equals(GET)){
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user