예제 #1
0
 /**
  * SnmpVar转化Mac地址
  *
  * @param var
  * @return
  */
 public static String snmpvar2Mac(SnmpVar var) {
   byte[] bytes = var.toBytes();
   if (bytes.length == 6) {
     return ByteFormatter.convertStringInHextoASCII(var.toBytes());
   } else if (bytes.length == 17) {
     String str = var.toString();
     return str.replaceAll(":", "-");
   } else return var.toString();
 }
예제 #2
0
 /**
  * SnmpVar转换为DateTime类型
  *
  * @param var
  * @return
  */
 public static String snmpVar2DateAndTime(SnmpVar var) {
   // 添加对于系统运行时间是int型的处理,一般是非标准设备比如C2000
   if (var instanceof SnmpGauge) {
     SnmpGauge gauge = (SnmpGauge) var;
     return convertLong2DateTime(gauge.longValue());
   }
   byte[] bytes = var.toBytes();
   int i = bytes.length;
   byte abyte0[] = new byte[i * 2];
   int j = 0;
   for (int k = 0; k < bytes.length; k++) {
     abyte0[j] = (byte) (bytes[k] >> 4 & 15);
     abyte0[++j] = (byte) (bytes[k] & 15);
     j++;
   }
   i = abyte0.length;
   if (i != 16 && i != 22) {
     return null;
   }
   String s = "";
   j = abyte0[0] * 4096 + abyte0[1] * 256 + abyte0[2] * 16 + abyte0[3];
   s = s + j + "-";
   int k = abyte0[4] * 16 + abyte0[5];
   s = s + k + "-";
   int l = abyte0[6] * 16 + abyte0[7];
   s = s + l + ",";
   int i1 = abyte0[8] * 16 + abyte0[9];
   s = s + i1 + ":";
   int j1 = abyte0[10] * 16 + abyte0[11];
   s = s + j1 + ":";
   int k1 = abyte0[12] * 16 + abyte0[13];
   s = s + k1 + ".";
   int l1 = abyte0[14] * 16 + abyte0[15];
   s = s + l1;
   if (i > 16 && i != 32) {
     s = s + ",";
     char c = (char) (abyte0[16] * 16 + abyte0[17]);
     s = s + c;
     int i2 = abyte0[18] * 16 + abyte0[19];
     s = s + i2 + ":";
     int j2 = abyte0[20] * 16 + abyte0[21];
     s = s + j2;
   }
   return s;
 }