/**
* 获取unix网卡的mac地址.
* 非windows的系统默认调用本方法获取.如果有特殊系统请继续扩充新的取mac地址方法.
* @return mac地址
*/
public static String getUnixMACAddress() {
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try {
process = Runtime.getRuntime().exec("ifconfig eth0");// linux下的命令,一般取eth0作为本地主网卡 显示信息中包含有mac地址信息
bufferedReader = new BufferedReader(new InputStreamReader(process
.getInputStream()));
String line = null;
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
index = line.toLowerCase().indexOf("hwaddr");// 寻找标示字符串[hwaddr]
if (index >= 0) {// 找到了
mac = line.substring(index +"hwaddr".length()+ 1).trim();// 取出mac地址并去除2边空格
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
return mac;
}
/**
* 获取widnows网卡的mac地址.
* @return mac地址
*/
public static String getWindowsMACAddress() {
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try {
process = Runtime.getRuntime().exec("ipconfig /all");// windows下的命令,显示信息中包含有mac地址信息
bufferedReader = new BufferedReader(new InputStreamReader(process
.getInputStream()));
String line = null;
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
index = line.toLowerCase().indexOf("physical address");// 寻找标示字符串[physical address]
if (index >= 0) {// 找到了
index = line.indexOf(":");// 寻找":"的位置
if (index>=0) {
mac = line.substring(index + 1).trim();// 取出mac地址并去除2边空格
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
return mac;
}
分享到:
相关推荐
获取客户端ip地址( 这个必须从客户端传到后台): jsp页面下,很简单,request....因为系统的VIew层是用JSF来实现的,因此页面上没法直接获得类似request,在bean里做了个强制转换java 获取客户端ip mac地址
获取用户请求IP地址 根据IP地址获取mac地址
java获取mac,通过命令获取裁剪后得到想要的内容
import java.net.Inet4Address; import java.net.InetAddress; import java.util.Arrays; import jpcap.*; import jpcap.packet.*; public class ARP { public static byte[] arp(InetAddress ip) throws java.io....
可以利用系统命令ipconfig/all,读取mac地址,然后通过解析行得到mac地址。
php与java获得电脑mac地址,根据不同系统获取,有window和linux
得到机器的MAC,硬盘序列序列号和IP地址 public static void main(String[] args) ...{ String osName = System.getProperty("os.name"); StringBuffer systemPathBuff = new StringBuffer(""); if (osName.index...
Java/JSP获得客户端网卡MAC地址的三种方法解析
java 程序, 亲测。 获取计算机的网卡IP地址。 runttime 的调用。
该jar工具包是通过DiskID.dll获取计算机硬盘序列号、分区卷标号、MAC地址、IP地址、计算机名称等的信息,获取内容如下: 计算机名称:201709071714 硬盘序列号:183534442995 C分区卷标号:29F513CB MAC地址:F0-A9-59-...
java中沒有直接得到mac地址的類 此類為自己編寫 調用時返回String類型的mac地址
//Java获得CPU序列号和网卡Mac地址 /* 利用Runtime call操作系统的命令,具体的命令取决于不同的操作系统,注意不要调用Runtime.getRuntime().exec(String)接口,要用Runtime.getRuntime().exec(String[])这个接口,...
本文给大家汇总介绍了下使用java实现获取客户端用户的MAC地址的方法,当然最后一种更全面一些,有需要的小伙伴们可以根据需求自由选择。
两种获取MAC地址的方法,一种是可以获得本机的MAC地址,另一个是通过ip地址获取远程客户端的MAC地址。
NULL 博文链接:https://hylong05.iteye.com/blog/560600
很容易就可以获得 机器的MAC地址,我这使用java编写的。
很容易的就可以获得机器的MAC(网卡)地址,是用java语言编写的
<br>LF-Spy能够自动测试目标Java服务器的网络连接速度、MAC地址、服务器硬盘剩余空间、服务器运算能力、服务器的内存资源损耗、cpu占用率、硬盘大小、页面执行时间等参数。并提供服务器基本信息,服务器组件支持...
JDK(Java Development Kit)是Sun Microsystems针对Java开发员的产品。自从Java推出以来,JDK已经成为使用最广泛的Java SDK。JDK 是整个Java的核心,包括了Java运行环境,Java工具和Java基础的类库。JDK是学好Java的...
java准确的获取操作系统的名称 java获取系统 os.name java系统名称 System使用 系统工具类 自己封装的Util类,功能强大,原理简单。 初学者可以下载下来进行学习。可以判断mac、linux、window等等系统。如win7,win8,...