差分
この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
programming:python:dpkt:start [2011/04/01 20:59] yuki |
— (現在) | ||
|---|---|---|---|
| ライン 1: | ライン 1: | ||
| - | ====== dpkt ====== | ||
| - | * パケット操作用。 | ||
| - | * http://code.google.com/p/dpkt/ | ||
| - | |||
| - | * Python 2.7.1でビルド | ||
| - | * http://dpkt.googlecode.com/files/dpkt-1.7.tar.gz | ||
| - | * <code>python setup.py config | ||
| - | python setup.py install</code> | ||
| - | |||
| - | * 例えば、「filenameで指定したpcapファイルのパケットを、GREでカプセル化して吐き出す」というのを適当に書くと以下のようになる。 | ||
| - | * <code>import sys | ||
| - | import dpkt | ||
| - | |||
| - | def ipv4addr(addr): | ||
| - | addrcode = [chr(int(i)) for i in addr.split('.')] | ||
| - | return "".join(addrcode) | ||
| - | |||
| - | def main(): | ||
| - | filename = "target.pcap" | ||
| - | |||
| - | pcr = dpkt.pcap.Reader(open(filename)) | ||
| - | gre = dpkt.gre.GRE() | ||
| - | ip = dpkt.ip.IP(src=ipv4addr('10.90.0.1'), dst=ipv4addr('10.90.0.2'), p=47) | ||
| - | eth = dpkt.ethernet.Ethernet(src='\x01\x02\x03\x04\x05\x06', dst='\x05\x06\x07\x08\x09\x0a', type=dpkt.ethernet.ETH_TYPE_IP) | ||
| - | |||
| - | pcw = dpkt.pcap.Writer(open('gre_'+filename,'wb')) | ||
| - | for ts, buf in pcr: | ||
| - | eth_in = dpkt.ethernet.Ethernet(buf) | ||
| - | gre.data = eth_in.data | ||
| - | ip.sum = 0 | ||
| - | ip.data = gre | ||
| - | ip.len = len(ip) | ||
| - | eth.data = ip | ||
| - | pcw.writepkt(eth,ts) | ||
| - | pcw.close | ||
| - | pass | ||
| - | |||
| - | if __name__ == '__main__': | ||
| - | main()</code> | ||
