java 获取windows Mac 和linux Mac
来源:互联网 发布:阿里云服务器添加域名 编辑:程序博客网 时间:2024/05/02 06:02
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Mac
{
public static String getOSName()
{
return System.getProperty("os.name").toLowerCase();
}
public static String getMACAddress(String commond, String regular)
{
Pattern pattern = Pattern.compile(regular); //windows "..-..-..-..-..-.."
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try
{
process = Runtime.getRuntime().exec(commond); //windows getmac
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = bufferedReader.readLine()) != null)
{
Matcher matcher = pattern.matcher(line);
if (matcher.find())
{
mac = matcher.group().replace("-", "");
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if (bufferedReader != null)
{
bufferedReader.close();
}
}
catch (IOException e1)
{
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
if (mac==null||mac.isEmpty())
{
InetAddress addr;
try
{
addr = InetAddress.getLocalHost();
mac=addr.getHostAddress().replace(".", "");//getIP
}
catch (UnknownHostException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return mac;
}
public static String GetMacs(){
String os = getOSName();
if (os.startsWith("windows"))
{
return getMACAddress("getmac", "..-..-..-..-..-..");
}
else
{
return getMACAddress("ifconfig", "..:..:..:..:..:..");
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Mac
{
public static String getOSName()
{
return System.getProperty("os.name").toLowerCase();
}
public static String getMACAddress(String commond, String regular)
{
Pattern pattern = Pattern.compile(regular); //windows "..-..-..-..-..-.."
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try
{
process = Runtime.getRuntime().exec(commond); //windows getmac
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = bufferedReader.readLine()) != null)
{
Matcher matcher = pattern.matcher(line);
if (matcher.find())
{
mac = matcher.group().replace("-", "");
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if (bufferedReader != null)
{
bufferedReader.close();
}
}
catch (IOException e1)
{
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
if (mac==null||mac.isEmpty())
{
InetAddress addr;
try
{
addr = InetAddress.getLocalHost();
mac=addr.getHostAddress().replace(".", "");//getIP
}
catch (UnknownHostException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return mac;
}
public static String GetMacs(){
String os = getOSName();
if (os.startsWith("windows"))
{
return getMACAddress("getmac", "..-..-..-..-..-..");
}
else
{
return getMACAddress("ifconfig", "..:..:..:..:..:..");
}
}
}
- java 获取windows Mac 和linux Mac
- Java中获取windows、Linux和windows7的MAC地址
- Java中获取windows、Linux和windows7的MAC地址
- Linux,Windows 和 Mac
- 获取mac地址和cpu id(windows和linux)
- 用纯Java代码根据IP获取windows和linux的MAC物理地址
- 漫谈 Linux,Windows 和 Mac
- 谈 Linux,Windows 和 Mac
- 谈 Linux,Windows 和 Mac
- 谈 Linux,Windows 和 Mac
- 谈 Linux,Windows 和 Mac
- 谈 Linux,Windows 和 Mac
- 谈 Linux,Windows 和 Mac
- linux和mac/windows文件传输
- java 获取IP和MAC
- java执行linux命令获取MAC和ip地址
- windows 获取mac
- ZZ-linux中获取IP和MAC
- java对象与json对象间的相互转换
- 国内一款优秀的开源HTML5图表绘制框架-ichartjs
- 一次Windows CE下调试内存泄露的经历
- java.sql.SQLException: 数字溢出
- PAT PMT 结构
- java 获取windows Mac 和linux Mac
- Android 4.0 ICS SystemUI浅析——StatusBar加载流程分析
- 图论之Havel定理 Frogs' Neighborhood (青蛙的邻居)
- yum安装及SVN配置
- 如何将word等office文件添加到右键的新建菜单
- 一个老业务员的经验
- 阿里订单故事
- hadoop hdfs的一些操作
- 生成固定长度的随机字符和数字