Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李苗
/
Vion-DevOps
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit aa428362
authored
Sep 03, 2024
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[add] IP 归属地添加省份
1 parent
3e318684
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
src/main/java/vion/utils/ip/IPUtil.java
src/main/java/vion/utils/ip/IPUtil.java
View file @
aa42836
...
...
@@ -2,6 +2,7 @@ package vion.utils.ip;
import
com.maxmind.db.CHMCache
;
import
com.maxmind.geoip2.DatabaseReader
;
import
com.maxmind.geoip2.record.AbstractNamedRecord
;
import
lombok.extern.slf4j.Slf4j
;
import
org.dromara.hutool.core.io.file.FileUtil
;
import
org.dromara.hutool.core.text.StrUtil
;
...
...
@@ -12,6 +13,7 @@ import java.net.InetAddress;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author vion
...
...
@@ -200,16 +202,18 @@ public class IPUtil {
var
asn
=
asnReader
.
asn
(
address
);
var
asnNum
=
asn
.
getAutonomousSystemNumber
();
var
asnOrg
=
asn
.
getAutonomousSystemOrganization
();
var
city
=
cityReader
.
city
(
address
);
var
cityName
=
city
.
getCity
().
getName
();
var
province
=
city
.
getSubdivisions
().
stream
().
map
(
AbstractNamedRecord:
:
getName
).
collect
(
Collectors
.
joining
(
","
));
var
country
=
cityReader
.
country
(
address
);
var
countryName
=
country
.
getCountry
().
getName
();
var
asnStr
=
asnMap
.
getOrDefault
(
asnNum
.
intValue
(),
asnOrg
);
return
StrUtil
.
format
(
"Country:{},
City:{}, ASN:{}"
,
countryNam
e
,
cityName
,
asnStr
);
return
StrUtil
.
format
(
"Country:{},
Province:{}, City:{}, ASN:{}"
,
countryName
,
provinc
e
,
cityName
,
asnStr
);
}
catch
(
Exception
e
)
{
log
.
error
(
"获取IP归属地失败:[{}],error:{}"
,
ip
,
e
.
getMessage
());
}
return
StrUtil
.
format
(
"Country:{},
City:{}, ASN:{}
"
,
"Unknown"
,
"Unknown"
,
"Unknown"
);
return
StrUtil
.
format
(
"Country:{},
Province:{}, City:{}, ASN:{}"
,
"Unknown
"
,
"Unknown"
,
"Unknown"
,
"Unknown"
);
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment