增加PCAP时间戳值

时间:2013-02-28 15:56:59

标签: python scapy

Scapy有capability来修改每个数据包的时间戳,因此我想知道为什么可能是通过指定起始值来修改PCAP中多个数据包的时间戳的最佳方法。我能够修改数据包但尚未成功递增微秒值。

例如,想要修改包含以下内容的PCAP中的数据包时间戳:

1360806997.231777 IP 192.168.1.100.50496 > 192.168.1.200.http: S 4211078664:4211078664(0) win 14600 <mss 1460,sackOK,timestamp 199086437 0,nop,wscale 3>
1360806997.231808 IP 192.168.1.200.http > 192.168.1.100.50496: S 256066681:256066681(0) ack 4211078665 win 14480 <mss 1460,sackOK,timestamp 199086195 199086437,nop,wscale 3>
1360806997.232034 IP 192.168.1.100.50496 > 192.168.1.200.http: . ack 1 win 1825 <nop,nop,timestamp 199086437 199086195>
1360806997.232043 IP 192.168.1.100.50496 > 192.168.1.200.http: P 1:19(18) ack 1 win 1825 <nop,nop,timestamp 199086437 199086195>
1360806997.232063 IP 192.168.1.200.http > 192.168.1.100.50496: . ack 19 win 1810 <nop,nop,timestamp 199086195 199086437>

以下内容:

1234567890.000000 IP 192.168.1.100.50496 > 192.168.1.200.http: S 4211078664:4211078664(0) win 14600 <mss 1460,sackOK,timestamp 199086437 0,nop,wscale 3>
1234567890.000001 IP 192.168.1.200.http > 192.168.1.100.50496: S 256066681:256066681(0) ack 4211078665 win 14480 <mss 1460,sackOK,timestamp 199086195 199086437,nop,wscale 3>
1234567890.000002 IP 192.168.1.100.50496 > 192.168.1.200.http: . ack 1 win 1825 <nop,nop,timestamp 199086437 199086195>
1234567890.000003 IP 192.168.1.100.50496 > 192.168.1.200.http: P 1:19(18) ack 1 win 1825 <nop,nop,timestamp 199086437 199086195>
1234567890.000004 IP 192.168.1.200.http > 192.168.1.100.50496: . ack 19 win 1810 <nop,nop,timestamp 199086195 199086437>

1 个答案:

答案 0 :(得分:1)

这似乎有效:

def process_packets():
    pkts = rdpcap(infile)
    cooked=[]
    timestamp = 1234567890.000000
    for p in pkts:
        p.time = timestamp
        timestamp += 0.000001
        pmod=p
        cooked.append(pmod)
    wrpcap("dump.pcap", cooked)

代码会将每个数据包的新时间值写入具有指定秒数的新PCAP,并递增微秒值。如果有更优雅的方法,请告诉我。