Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tts-client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周亚武
tts-client
Commits
ff0eb958
Commit
ff0eb958
authored
9 months ago
by
周亚武
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改mac读取方法
parent
f29d7d5a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
2 deletions
+135
-2
src/main/java/com/mortals/xhx/tts/UI/MainWindow.java
src/main/java/com/mortals/xhx/tts/UI/MainWindow.java
+2
-1
src/main/java/com/mortals/xhx/tts/UI/SettingWindow.java
src/main/java/com/mortals/xhx/tts/UI/SettingWindow.java
+3
-1
src/main/java/com/mortals/xhx/tts/utils/ReadMacAdrss.java
src/main/java/com/mortals/xhx/tts/utils/ReadMacAdrss.java
+130
-0
No files found.
src/main/java/com/mortals/xhx/tts/UI/MainWindow.java
View file @
ff0eb958
...
...
@@ -258,7 +258,8 @@ public class MainWindow {
pushInitMsg
(
"程序开始启动"
);
readConfig
();
if
(
deviceId
==
null
)
{
deviceId
=
MacAddressReader
.
getMacAddress
();
// deviceId = MacAddressReader.getMacAddress();
deviceId
=
ReadMacAdrss
.
getMacAddress
();
}
//读取本地配置文件
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/mortals/xhx/tts/UI/SettingWindow.java
View file @
ff0eb958
...
...
@@ -6,6 +6,7 @@ import com.google.gson.Gson;
import
com.google.gson.reflect.TypeToken
;
import
com.mortals.xhx.tts.bean.*
;
import
com.mortals.xhx.tts.utils.MacAddressReader
;
import
com.mortals.xhx.tts.utils.ReadMacAdrss
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.io.ClassPathResource
;
...
...
@@ -157,7 +158,8 @@ public class SettingWindow {
readConfig
();
if
(
deviceId
==
null
){
deviceId
=
MacAddressReader
.
getMacAddress
();
// deviceId = MacAddressReader.getMacAddress();
deviceId
=
ReadMacAdrss
.
getMacAddress
();
writeConfig
();
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/mortals/xhx/tts/utils/ReadMacAdrss.java
0 → 100644
View file @
ff0eb958
package
com.mortals.xhx.tts.utils
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* @author ZYW
* @date 2024-08-22 11:10
*/
public
class
ReadMacAdrss
{
public
static
final
boolean
isWindows
=
System
.
getProperty
(
"os.name"
)
.
startsWith
(
"Win"
);
public
static
final
boolean
isLinux
=
System
.
getProperty
(
"os.name"
).
equals
(
"Linux"
);
public
static
final
boolean
isAIX
=
System
.
getProperty
(
"os.name"
).
equals
(
"AIX"
);
public
static
final
boolean
isSolaris
=
(
System
.
getProperty
(
"os.name"
)
.
equals
(
"Solaris"
))
||
(
System
.
getProperty
(
"os.name"
).
equals
(
"SunOS"
));
public
static
final
boolean
isHPUX
=
System
.
getProperty
(
"os.name"
).
equals
(
"HP-UX"
);
public
static
final
String
WindowsCmd
=
"cmd.exe /c ipconfig/all"
;
public
static
final
String
LinuxCmd
=
"ifconfig -a"
;
public
static
final
String
AIXCmd
=
"netstat -ia"
;
public
static
final
String
SolarisCmd
=
"/sbin/ifconfig -a"
;
public
static
final
String
HPUXCmd
=
"/usr/sbin/lanscan"
;
private
static
String
mPhysicalAddress
=
""
;
private
static
int
mPhysicalMacNumber
=
0
;
private
static
boolean
isInit
=
false
;
public
static
String
getMacAddress
()
{
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
getMacCommand
());
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
Pattern
macPattern
=
Pattern
.
compile
(
getRegStr
());
String
line
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
if
(
""
.
equals
(
line
))
continue
;
Matcher
macMatcher
=
macPattern
.
matcher
(
line
);
boolean
result
=
macMatcher
.
find
();
if
(
result
)
{
mPhysicalMacNumber
+=
1
;
String
mac
=
macMatcher
.
group
(
0
);
mac
=
mac
.
replace
(
':'
,
'-'
);
if
(
isHPUX
)
{
mac
=
dealMac
(
mac
);
return
mac
;
}
if
(
""
.
equals
(
mPhysicalAddress
))
{
mPhysicalAddress
=
mac
;
return
mac
;
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
isInit
=
true
;
return
"未找到mac"
;
}
public
static
String
getMacCommand
()
{
if
(
isWindows
)
{
return
"cmd.exe /c ipconfig/all"
;
}
if
(
isLinux
)
{
return
"ifconfig -a"
;
}
if
(
isAIX
)
{
return
"netstat -ia"
;
}
if
(
isSolaris
)
{
return
"/sbin/ifconfig -a"
;
}
if
(
isHPUX
)
{
return
"/usr/sbin/lanscan"
;
}
return
""
;
}
public
static
String
getRegStr
()
{
if
(
isWindows
)
{
return
"([0-9A-Fa-f]{2})(-[0-9A-Fa-f]{2}){5}"
;
}
if
(
isLinux
)
{
return
"([0-9A-Fa-f]{2})(:[0-9A-Fa-f]{2}){5}"
;
}
if
(
isAIX
)
{
return
"([0-9A-Fa-f]{2})(:[0-9A-Fa-f]{2}){5}"
;
}
if
(
isSolaris
)
{
return
"([0-9A-Fa-f]{2})(:[0-9A-Fa-f]{2}){5}"
;
}
if
(
isHPUX
)
{
return
"0x[0-9a-zA-Z]{12}"
;
}
return
""
;
}
public
static
String
dealMac
(
String
mac
)
{
mac
=
mac
.
substring
(
2
);
StringBuffer
sAdd
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
12
;
++
i
)
{
sAdd
.
append
(
mac
.
charAt
(
i
));
if
(
i
%
2
==
1
)
{
sAdd
.
append
(
"-"
);
}
}
return
sAdd
.
substring
(
0
,
sAdd
.
length
()
-
1
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment