Почему стоит избегать вложенных блоков в функции? (PHP) [закрыто]

Ну, с scapy я придумал следующее (извините за мой Python). Надеюсь, это поможет кому-то. Был возможный более простой сценарий, когда все пакеты из файла pcap считываются в память, но это может привести к проблемам с большими файлами захвата.

from scapy.all import *
global src_ip, dst_ip
src_ip = 1.1.1.1
dst_ip = 2.2.2.2
infile = "dump.pcap"

try:
    my_reader = PcapReader(infile)
    my_send(my_reader)
except IOError:
    print "Failed reading file %s contents" % infile
    sys.exit(1)

def my_send(rd, count=100):
    pkt_cnt = 0
    p_out = []

    for p in rd:
        pkt_cnt += 1
        np = p.payload
        np[IP].dst = dst_ip
        np[IP].src = src_ip
        del np[IP].chksum
        p_out.append(np)
        if pkt_cnt % count == 0:
            send(PacketList(p_out))
            p_out = []

    # Send remaining in final batch
    send(PacketList(p_out))
    print "Total packets sent %d" % pkt_cn
16
задан musicliftsme 15 August 2013 в 16:06
поделиться