catch(SocketException se){
System.err.println("错误:"+se.getMessage());
}
}
private static String bytes2mac(byte[] bytes){
//MAC地址应为6字节
if(bytes.length!=6){
System.err.println("MAC地址数据有错!");
return null;
}
StringBuffer macString=new StringBuffer();
byte currentByte;
for(int i=0;i<bytes.length;i++){
//与11110000作按位与运算以便读取当前字节高4位
currentByte=(byte)((bytes[i]&240)>>4); macString.append(Integer.toHexString(currentByte));
//与00001111作按位与运算以便读取当前字节低4位
currentByte=(byte)((bytes[i]&15));
macString.append(Integer.toHexString(currentByte));
//追加字节分隔符“-”
macString.append("-");
}
//删除多加的一个“-”
macString.delete(macString.length()-1,macString.length());
//统一转换成大写形式后返回 return macString.toString().toUpperCase();
|