怎么用JAVA读取电脑的物理地址(不能更改的物理地址)
不要网卡物理地址 ,网卡的物理地址可以人工改变
怎么用JAVA读取电脑的物理地址(不能更改的物理地址)
答案:3 悬赏:0 手机版
解决时间 2021-03-10 05:33
- 提问者网友:椧運幽默
- 2021-03-09 12:49
最佳答案
- 五星知识达人网友:蕴藏春秋
- 2021-03-09 14:11
转自别人的 代码
import java.io.*;
import java.util.*;
public class ProcessBuilderShow{
public static List getPhysicalAddress(){
Process p = null;
//物理网卡列表
List address = new ArrayList();
try{
//执行ipconfig /all命令
p = new ProcessBuilder("ipconfig", "/all").start();
}catch (IOException e){
return address;
}
byte[] b = new byte[1024];
StringBuffer sb = new StringBuffer();
//读取进程输出值
InputStream in = p.getInputStream();
try{
while (in.read(b)>0){
sb.append(new String(b));
}
}catch (IOException e1){
}finally{
try{
in.close();
}catch (IOException e2){
}
}
//以下分析输出值,得到物理网卡
String rtValue = sb.substring(0);
int i = rtValue.indexOf("Physical Address. . . . . . . . . :");
while(i>0){
rtValue = rtValue.substring(i + "Physical Address. . . . . . . . . :".length());
address.add(rtValue.substring(0,18));
i = rtValue.indexOf("Physical Address. . . . . . . . . :");
}
return address;
}
public static void main(String[] args){
List address = ProcessBuilderShow.getPhysicalAddress();
for(String add:address){
System.out.printf("物理网卡地址:%s%n", add);
}
}
}
import java.io.*;
import java.util.*;
public class ProcessBuilderShow{
public static List
Process p = null;
//物理网卡列表
List
try{
//执行ipconfig /all命令
p = new ProcessBuilder("ipconfig", "/all").start();
}catch (IOException e){
return address;
}
byte[] b = new byte[1024];
StringBuffer sb = new StringBuffer();
//读取进程输出值
InputStream in = p.getInputStream();
try{
while (in.read(b)>0){
sb.append(new String(b));
}
}catch (IOException e1){
}finally{
try{
in.close();
}catch (IOException e2){
}
}
//以下分析输出值,得到物理网卡
String rtValue = sb.substring(0);
int i = rtValue.indexOf("Physical Address. . . . . . . . . :");
while(i>0){
rtValue = rtValue.substring(i + "Physical Address. . . . . . . . . :".length());
address.add(rtValue.substring(0,18));
i = rtValue.indexOf("Physical Address. . . . . . . . . :");
}
return address;
}
public static void main(String[] args){
List
for(String add:address){
System.out.printf("物理网卡地址:%s%n", add);
}
}
}
全部回答
- 1楼网友:山君与见山
- 2021-03-09 16:23
java jpcap 编程可以得到物理地址,以及网卡信息。
- 2楼网友:三千妖杀
- 2021-03-09 15:06
你好!
java直接是读不了的,可以通过jni来实现,用c来读取
我的回答你还满意吗~~
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯