取得原数据包如下:
No. Time Source Destination Protocol Info
2188 18.000397 11.84.17.121 11.84.17.26 Syslog LPR.INFO: Aug 24 11:34:13 SymantecServer XNPBCNSEP: hdffwl,\346\234\254\345\234\260: 0.0.0.0,\346\234\254\345\234\260: 8192,\346\234\254\345\234\260: 01000CCCCCCC,\350\277\234\347\250\213: 0.0.0.0,\350\277\234\347\250\213: ,\350\277\234\347\250\213: 0,\350\277\234\347\250\213: 000AB749E790,\345\205\266\344\273\226,1,\345\274\200\345\247\213: 2010-08-24 11:33:46,\347\273\223\346\235\237: 2010-08-24 11:33:46,\345\207\272\347\216\260\346\254\241\346\225\260: 1,\345\272\224\347\224\250\347\250\213\345\272\217: ,\350\247\204\345\210\231: \347\246\201\346\255\242\346\211\200\346\234\211\345\205\266\344\273\226\351\200\232\344\277\241,\344\275\215\347\275\256: \351\273\230\350\256\244\345\200\274,\347\224\250\346\210\267: hdffwl1,\345\237\237: HDFFWL,\346\223\215\344\275\234: \345\267\262\347\246\201\346\255\242
Frame 2188 (393 bytes on wire, 393 bytes captured)
Ethernet II, Src: Ibm_36:28:be (00:21:5e:36:28:be), Dst: 18:a9:05:4b:d8:32 (18:a9:05:4b:d8:32)
Internet Protocol, Src: 11.84.17.121 (11.84.17.121), Dst: 11.84.17.26 (11.84.17.26)
User Datagram Protocol, Src Port: ccs-software (2734), Dst Port: syslog (514)
[truncated] Syslog message: LPR.INFO: Aug 24 11:34:13 SymantecServer XNPBCNSEP: hdffwl,\346\234\254\345\234\260: 0.0.0.0,\346\234\254\345\234\260: 8192,\346\234\254\345\234\260: 01000CCCCCCC,\350\277\234\347\250\213: 0.0.0.0,\350\277\234\3
需要转换成中文,代码如下:
String message = "hdffwl,\\346\\234\\254\\345\\234\\260: 0.0.0.0,\\346\\234\\254\\345\\234\\260: 8192,\\346\\234\\254\\345\\234\\260: 01000CCCCCCC,\\350\\277\\234\\347\\250\\213: 0.0.0.0";
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ByteArrayInputStream inputStream = new ByteArrayInputStream(message.getBytes());
int read = -1;
byte[] byte3 = new byte[3];
while ((read = inputStream.read()) > -1) {
if (read == '\\') {
try {
inputStream.read(byte3);
} catch (IOException e) {
e.printStackTrace();
}
outputStream.write(Integer.parseInt(new String(byte3),8));
}
else {
outputStream.write(read);
}
}
String decodeMessage = null;
try {
decodeMessage = new String(outputStream.toByteArray(),"utf-8");
} catch (UnsupportedEncodingException e) {
}
System.out.println(decodeMessage);
最后打印如下:
hdffwl,本地: 0.0.0.0,本地: 8192,本地: 01000CCCCCCC,远程: 0.0.0.0