Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
Nse
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
吴超
Nse
Commits
5b37b243
Commit
5b37b243
authored
Aug 28, 2025
by
周海峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
ec36cc0e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
67 行增加
和
70 行删除
+67
-70
src/main/java/com/chenyang/nse/bussiness/tools/licensekey/LicenseKeyTool.java
+67
-70
没有找到文件。
src/main/java/com/chenyang/nse/bussiness/tools/licensekey/LicenseKeyTool.java
View file @
5b37b243
...
...
@@ -18,15 +18,8 @@ import java.net.SocketException;
import
java.sql.SQLException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.*
;
import
org.apache.commons.collections.map.HashedMap
;
public
class
LicenseKeyTool
{
...
...
@@ -100,22 +93,13 @@ public class LicenseKeyTool {
map
.
put
(
"endDatelicensekey"
,
endDatelicensekey
);
map
.
put
(
"projectNum"
,
projectNum
);
Log
.
info
(
"校验的证书是不是失效--UUID"
);
List
linuxLocalUUID
=
getLinuxLocalUUID
();
List
<
String
>
linuxLocalUUID
=
getLinuxLocalUUID
();
String
mac
=
getLocalMacLiunx
();
boolean
b
=
false
;
Log
.
info
(
"校验的证书是不是失效--linuxLocalUUID"
+
linuxLocalUUID
);
for
(
int
i
=
0
;
i
<
linuxLocalUUID
.
size
();
++
i
)
{
String
localUUid
=
(
String
)
linuxLocalUUID
.
get
(
i
);
System
.
out
.
println
(
localUUid
+
"=="
+
licUUid
);
Log
.
info
(
localUUid
+
"=="
+
licUUid
);
if
(
licUUid
.
equalsIgnoreCase
(
localUUid
)
&&
licInfoMac
.
equalsIgnoreCase
(
mac
))
{
Log
.
info
(
"成功"
);
b
=
true
;
break
;
}
}
boolean
matchMac
=
Arrays
.
stream
(
mac
.
split
(
","
)).
anyMatch
(
licInfoMac:
:
equalsIgnoreCase
);
boolean
matchIp
=
linuxLocalUUID
.
stream
().
anyMatch
(
licUUid:
:
equalsIgnoreCase
);
b
=
matchMac
&&
matchIp
;
if
(!
b
)
{
resultVO
.
setMessage
(
"uuid有误"
);
resultVO
.
setResult
(
false
);
...
...
@@ -158,6 +142,10 @@ public class LicenseKeyTool {
}
}
/**
* 获取本机器的ip地址
* @return list
*/
public
static
List
<
String
>
getLinuxLocalUUID
()
{
List
<
String
>
resultList
=
new
ArrayList
<>();
String
os
=
System
.
getProperty
(
"os.name"
).
toLowerCase
();
...
...
@@ -201,76 +189,85 @@ public class LicenseKeyTool {
}
reader
.
close
();
}
catch
(
IOException
e
)
{
Log
.
info
(
"
校验的证书是不是失效--linuxLocalUUID
"
+
e
.
getMessage
());
Log
.
info
(
"
Linux获取ip
"
+
e
.
getMessage
());
}
}
return
resultList
;
}
public
static
List
getLinuxLocalIp
()
throws
SocketException
{
List
<
String
>
ipList
=
new
ArrayList
();
String
ip
=
""
;
try
{
Enumeration
<
NetworkInterface
>
en
=
NetworkInterface
.
getNetworkInterfaces
();
while
(
en
.
hasMoreElements
())
{
NetworkInterface
intf
=
(
NetworkInterface
)
en
.
nextElement
();
String
name
=
intf
.
getName
();
if
(!
name
.
contains
(
"docker"
)
&&
!
name
.
contains
(
"lo"
))
{
Enumeration
<
InetAddress
>
enumIpAddr
=
intf
.
getInetAddresses
();
while
(
enumIpAddr
.
hasMoreElements
())
{
InetAddress
inetAddress
=
(
InetAddress
)
enumIpAddr
.
nextElement
();
if
(!
inetAddress
.
isLoopbackAddress
())
{
String
ipaddress
=
inetAddress
.
getHostAddress
().
toString
();
if
(!
ipaddress
.
contains
(
"::"
)
&&
!
ipaddress
.
contains
(
"0:0:"
)
&&
!
ipaddress
.
contains
(
"fe80"
))
{
ipList
.
add
(
ipaddress
);
}
}
}
}
}
}
catch
(
SocketException
ex
)
{
ip
=
"127.0.0.1"
;
ex
.
printStackTrace
();
}
return
ipList
;
}
/**
* 获取本机MAC地址
* @return list
* @throws SocketException
*/
public
static
String
getLocalMacLiunx
()
throws
SocketException
{
String
mac
=
""
;
Set
<
String
>
macSet
=
new
HashSet
<>();
try
{
Process
p
=
(
new
ProcessBuilder
(
new
String
[]{
"ifconfig"
})).
start
();
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
p
.
getInputStream
()));
String
line
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
Pattern
pat
=
Pattern
.
compile
(
"\\b\\w+:\\w+:\\w+:\\w+:\\w+:\\w+\\b"
);
Matcher
mat
=
pat
.
matcher
(
line
);
if
(
mat
.
find
())
{
mac
=
mat
.
group
(
0
);
Enumeration
<
NetworkInterface
>
networks
=
NetworkInterface
.
getNetworkInterfaces
();
while
(
networks
.
hasMoreElements
())
{
NetworkInterface
network
=
networks
.
nextElement
();
if
(!
network
.
isLoopback
()
&&
network
.
getHardwareAddress
()
!=
null
)
{
byte
[]
macBytes
=
network
.
getHardwareAddress
();
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
macBytes
.
length
;
i
++)
{
sb
.
append
(
String
.
format
(
"%02x"
,
macBytes
[
i
]));
if
(
i
<
macBytes
.
length
-
1
)
{
sb
.
append
(
":"
);
}
}
System
.
out
.
println
(
"["
+
sb
.
toString
()+
"]"
);
macSet
.
add
(
sb
.
toString
());
}
}
br
.
close
();
}
catch
(
IOException
var6
)
{
}
catch
(
SocketException
e
)
{
System
.
out
.
println
(
"获取MAC地址失败: "
+
e
.
getMessage
());
}
mac
=
String
.
join
(
","
,
macSet
);
System
.
out
.
println
(
"本机MAC地址为:\n"
+
mac
);
return
mac
;
}
// public static String getLocalMacLiunx() throws SocketException {
// String mac = "";
//
// try {
// Process p = (new ProcessBuilder(new String[]{"ifconfig"})).start();
// BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
//
// String line;
// while((line = br.readLine()) != null) {
// Pattern pat = Pattern.compile("\\b\\w+:\\w+:\\w+:\\w+:\\w+:\\w+\\b");
// Matcher mat = pat.matcher(line);
// if (mat.find()) {
// mac = mat.group(0);
// }
// }
//
// br.close();
// } catch (IOException var6) {
// }
//
// System.out.println("本机MAC地址为:\n" + mac);
// return mac;
// }
public
static
void
main
(
String
[]
args
)
{
// String content = "有效期1个月,10.10.200.24,fe:fc:fe:21:01:2d,2024-12-11,2025-01-11,5";
String
content
=
"有效期1
个月,172.16.100.75,3a:8f:fa:94:67:1a,2024-12-11,2025-11
-11,100"
;
String
content
=
"有效期1
2个月,172.16.100.75,bc:d0:74:a5:4d:b7,2024-12-11,2025-12
-11,100"
;
String
password
=
"ghca"
;
System
.
out
.
println
(
"加密之前:"
+
content
);
String
encrypt
=
AesTool
.
encrypt
(
content
,
password
);
System
.
out
.
println
(
"加密后的内容:"
+
encrypt
);
String
decrypt
=
AesTool
.
decrypt
(
encrypt
,
password
);
System
.
out
.
println
(
"解密后的内容:"
+
new
String
(
decrypt
));
// List<String> linuxLocalUUID = getLinuxLocalUUID();
// System.out.println(linuxLocalUUID);
// try {
// String localMacLiunx = getLocalMacLiunx();
// System.out.println(localMacLiunx);
// } catch (SocketException e) {
// throw new RuntimeException(e);
// }
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论