需要应用哪些包?用什么方法实现?
最好能给出一点代码例子。
谢谢
------解决方案--------------------
mark
------解决方案--------------------
sigar
------解决方案--------------------
关注学习
------解决方案--------------------
关注中
------解决方案--------------------
RunTime.getRunTime().exec( "ipconfig /all ")
可以得到本机的网卡的MAC地址.
------解决方案--------------------
学习
------解决方案--------------------
/*
* 创建日期 2007-2-12
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
import java.io.*;
import java.net.InetAddress;
public class GetMac
{
//通过IP获取网卡地址
public String getMacByIP(String serverIP)
{
String str = " ";
String macAddress = " ";
try
{
Process pp = Runtime.getRuntime().exec( "nbtstat -A "+serverIP);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for(int i = 1;i < 100;i++)
{
str = input.readLine();
if(str != null)
{
if(str.indexOf( "MAC Address ") > 1)
{
macAddress = str.substring(str.indexOf( "MAC Address ")+14,str.length());
break;
}
}
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
return macAddress;
}
//通过机器名获取网卡地址
public String getMacByServerName(String serverName)
{
String str = " ";
String macAddress = " ";
try
{
Process pp = Runtime.getRuntime().exec( "nbtstat -a "+serverName);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
for(int i = 1;i < 100;i++)
{
str = input.readLine();
if(str != null)
{
if(str.indexOf( "MAC Address ") > 1)
{
macAddress = str.substring(str.indexOf( "MAC Address ")+14,str.length());
break;
}
}
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
return macAddress;
}
public static void main(String[] args)
{
try
{
GetMac getmac;
getmac=new GetMac();
String mac= " ";
mac=getmac.getMacByIP( "192.168.1.57 ");
System.out.println(mac);
mac=getmac.getMacByServerName( "server ");
System.out.println(mac);
}
catch( Exception e )
{
System.out.println( e.getMessage() );
}
}
}
------解决方案--------------------
mark
------解决方案--------------------
谢谢,学习中
------解决方案--------------------
学习