Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hnxtbaboot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨亮
hnxtbaboot
Commits
4bf5d6ee
Commit
4bf5d6ee
authored
Apr 28, 2020
by
焦荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改客户端采集功能
parent
af523683
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
53 deletions
+30
-53
src/main/java/com/founder/utils/SysUitl.java
+30
-53
No files found.
src/main/java/com/founder/utils/SysUitl.java
View file @
4bf5d6ee
...
...
@@ -117,44 +117,41 @@ public class SysUitl {
return
mac
;
}
/*获取服务器端的MAC
public static String getMacAddress()
{
//根据 nbtstat -A 通过客户端IP获取MAC
public
static
String
getkhdMac
(
String
ip
){
String
mac
=
""
;
String line = "";
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows"))
{
try
{
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK"));
while((line = br.readLine()) != null)
{
System.out.println("==www=" + line);
//if (line.indexOf("Physical Address" ) > 0)
if (line.indexOf("物理地址" ) > 0 || line.indexOf("Physical Address" )>0)
{
int index = line.indexOf(":") + 2;
mac = line.substring(index);
try
{
Process
p
=
null
;
try
{
String
comstr
=
"nbtstat -A "
+
ip
;
p
=
Runtime
.
getRuntime
().
exec
(
comstr
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
InputStreamReader
ir
=
new
InputStreamReader
(
p
.
getInputStream
(),
"GBK"
);
LineNumberReader
input
=
new
LineNumberReader
(
ir
);
p
.
waitFor
();
boolean
flag
=
true
;
while
(
flag
)
{
String
str
=
input
.
readLine
();
// MAC 地址 = 48-8A-D2-42-5C-D8
if
(
str
!=
null
&&
str
.
indexOf
(
"MAC"
)
>
1
)
{
int
start
=
str
.
indexOf
(
"="
);
if
(
start
!=
-
1
)
{
mac
=
str
.
substring
(
start
+
1
).
trim
();
}
break
;
}
else
if
(
str
==
null
){
break
;
}
}
br.close();
} catch (IOException e) {}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
System
.
out
);
}
return
mac
;
}
*/
}
//获取MAC地址的方法
//获取
服务端
MAC地址的方法
public
static
String
getMACAddress
(){
//获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。
byte
[]
mac
=
new
byte
[
0
];
...
...
@@ -187,28 +184,8 @@ public class SysUitl {
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
,
SocketException
{
//String ip = "192.068.0.103";
//System.out.println("===" + getMac(ip));
// TODO Auto-generated method stub
/* InetAddress ia=null;
try {
ia=ia.getLocalHost();
String localname=ia.getHostName();
String localip=ia.getHostAddress();
System.out.println("本机名称是:"+ localname);
System.out.println("本机的ip是 :"+localip);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InetAddress ia1 = InetAddress.getLocalHost();//获取本地IP对象
try {
System.out.println("MAC ......... "+getMACAddress(ia1));
} catch (Exception e) {
e.printStackTrace();
}*/
System
.
out
.
println
(
"MAC ......... "
+
getMACAddress
());
String
ip
=
"192.168.0.103"
;
System
.
out
.
println
(
"==="
+
getkhdMac
(
ip
));
}
...
...
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