作者:电脑信息网日期:
返回目录:win7问题
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /f %%a in ('wmic nicconfig where^回(ipenabled^=true^) get index^|答findstr [0-99]') do set i=%%a
for /f %%a in ('wmic nicconfig where^(index^=%i%^) get macaddress^|findstr [0-99]') do set a=%%a &set a=!a::=!
echo %a%
pause
import java.net.*;
class Ipconfig{
public static void main(String[] arguments) throws Exception{
InetAddress ia = InetAddress.getLocalHost();//获取本地IP对象
System.out.println("MAC ......... "+getMACAddress(ia));
}
//获取MAC地址的方法
private static String getMACAddress(InetAddress ia)throws Exception{
//获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。
byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress();
//下面代7a64e4b893e5b19e362码是把mac地址拼装成String
StringBuffer sb = new StringBuffer();
for(int i=0;i<mac.length;i++){
if(i!=0){
sb.append("-");
}
//mac[i] & 0xFF 是为了把byte转化为正整数
String s = Integer.toHexString(mac[i] & 0xFF);
sb.append(s.length()==1?0+s:s);
}
//把字符串所有小写字母改为大写成为正规的mac地址并返回
return sb.toString().toUpperCase();
}
}
不知道win7下GetNet.dll是否好使
//通过域名得到7a686964616fe58685e5aeb9365IP
Function String GetIp(String Name) Library "GetNet.dll"
//得到本机IP地址
Function String GetLocalIp() Library "GetNet.dll"
//通过ip得到域名
Function String GetName(String ip) Library "GetNet.dll"
//得到本机域名
Function String GetLocalName() Library "GetNet.dll"
//得到局域网内的计算机名
Function String GetLanComputers() Library "GetNet.dll"
//得到局域网内的计算MAC
Function String GetMac(String ip) Library "GetNet.dll"
//得到本机的计算MAC
Function String GetLocalMac() Library "GetNet.dll"