2014-02-14 279 views
8

嗨,我的应用程序的工作,我必须读取它的网络工作现场包 打开它。并以复杂的方式显示它。转换TXT分组数据PCAP格式由Wireshark的

问题是我有包,但它是在文本文件,所以要打开它 通过Wireshark的我不得不它转换成.pcap格式

那么如何将文本中的数据包转换为pcap格式。

我的文本文件格式是这样如下图所示,

Frame: 
Frame:   number = 0 
Frame:  timestamp = 2014-02-13 09:39:11.288 
Frame:  wire length = 174 bytes 
Frame: captured length = 174 bytes 
Frame: 
Eth: ******* Ethernet - "Ethernet" - offset=0 (0x0) length=14 
Eth: 
Eth:  destination = 01:00:5e:7f:ff:fa 
Eth:     .... ..0. .... .... = [0] LG bit 
Eth:     .... ...0 .... .... = [0] IG bit 
Eth:   source = ec:9a:74:4d:8e:03 
Eth:     .... ..0. .... .... = [0] LG bit 
Eth:     .... ...0 .... .... = [0] IG bit 
Eth:    type = 0x800 (2048) [ip version 4] 
Eth: 
Ip: ******* Ip4 - "ip version 4" - offset=14 (0xE) length=20 protocol suite=NETWORK 
Ip: 
Ip:   version = 4 
Ip:    hlen = 5 [5 * 4 = 20 bytes, No Ip Options] 
Ip:   diffserv = 0x0 (0) 
Ip:     0000 00.. = [0] code point: not set 
Ip:     .... ..0. = [0] ECN bit: not set 
Ip:     .... ...0 = [0] ECE bit: not set 
Ip:   length = 160 
Ip:    id = 0x4CD1 (19665) 
Ip:   flags = 0x0 (0) 
Ip:     0.. = [0] reserved 
Ip:     .0. = [0] DF: do not fragment: not set 
Ip:     ..0 = [0] MF: more fragments: not set 
Ip:   offset = 0 
Ip:    ttl = 0 [time to live] 
Ip:    type = 17 [next: User Datagram] 
Ip:   checksum = 0xB0AA (45226) [correct] 
Ip:   source = 124.125.80.90 
Ip:  destination = 239.255.255.250 
Ip: 
Udp: ******* Udp offset=34 (0x22) length=8 
Udp: 
Udp:   source = 58845 
Udp:  destination = 1900 
Udp:   length = 140 
Udp:   checksum = 0x5154 (20820) [correct] 
Udp: 
Data: ******* Payload offset=42 (0x2A) length=132 
Data: 
002a: 4d 2d 53 45 41 52 43 48 20 2a 20 48 54 54 50 2f M-SEARCH * HTTP/ 
003a: 31 2e 31 0d 0a 48 6f 73 74 3a 32 33 39 2e 32 35 1.1..Host:239.25 
004a: 35 2e 32 35 35 2e 32 35 30 3a 31 39 30 30 0d 0a 5.255.250:1900.. 
005a: 53 54 3a 75 72 6e 3a 73 63 68 65 6d 61 73 2d 75 ST:urn:schemas-u 
006a: 70 6e 70 2d 6f 72 67 3a 64 65 76 69 63 65 3a 57 pnp-org:device:W 
007a: 41 4e 43 6f 6e 6e 65 63 74 69 6f 6e 44 65 76 69 ANConnectionDevi 
008a: 63 65 3a 31 0d 0a 4d 61 6e 3a 22 73 73 64 70 3a ce:1..Man:"ssdp: 
009a: 64 69 73 63 6f 76 65 72 22 0d 0a 4d 58 3a 33 0d discover"..MX:3. 
00aa: 0a 0d 0a 00 
+0

1-从您的结尾直接通过WireShark读取数据包不可行吗? 2-你如何得到这个文本文件? – Gyan

+1

您是否尝试过使用Java pcap库? –

回答

1

Wireshark的提供文本文件的命令行PCAP转换器:

https://www.wireshark.org/docs/man-pages/text2pcap.html

AutoHotkey的解决方案:

; Change appropriate file locations 
Run, %A_ProgramFiles%\ethereal\text2pcap.exe c:\test.txt c:\testconv.cap,%A_ProgramFiles%\ethereal 

如果你想做一个完全自动的解决方案,你可以修改这个函数,它主动监视一个目录的文件修改/创建。

http://www.autohotkey.com/board/topic/41653-watchdirectory/

0

如果您已经捕获原始数据包,你可以与他们直接写信给PCAP文件格式(见man 5 pcap-savefile),或使用hexdump都/ XXD + text2pcap实用程序ahkcoder建议。 Text2pcap还支持生成虚拟L2-4头(ethernet,ip,tcp/udp/sctp)。如果你只有文本表示,你可以从它重建数据包(所以,为你的系统中使用的每个协议生成所有适当的头文件)或者调整十六进制转储部分偏移量(从0000开始),并将其提供给text2pcap 。

+0

有没有Java解决方案? –

+0

我没有看到任何。这是一个简单而具体的问题,所以perl/bash/python/ruby​​可以成为很好的语言来解决它。 –