How to use the pypacker.ip.IP function in pypacker

To help you get started, we’ve selected a few pypacker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mike01 / pypacker / tests / old / test_perf_old.py View on Github external
"""
pypacker: 14915.2445937 pps
pypacker (manual): 15494.3632903 pps
impacket: 3929.30572776 pps
openbsd.packet: 1503.7928579 pps
scapy: 348.449269721 pps
xstruct: 88314.8953732 pps
"""
    src = dnet.addr('1.2.3.4').ip
    dst = dnet.addr('5.6.7.8').ip
    data = 'hello world'

    start = time.time()
    for i in range(cnt):
        dnet.ip_checksum(
            str(pypacker.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP,
                         len = dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN + len(data),
                         data=pypacker.udp.UDP(sport=111, dport=222,
                                       ulen=dnet.UDP_HDR_LEN + len(data),
                                       data=data))))
    print("pypacker: %s pps" % (cnt / (time.time() - start)) )
    
    start = time.time()
    for i in range(cnt):
        dnet.ip_checksum(str(pypacker.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP,
                                     len=dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN +
                                     len(data))) +
                         str(pypacker.udp.UDP(sport=111, dport=222,
                                      ulen=dnet.UDP_HDR_LEN + len(data))) +
                         data)
    print("pypacker (manual): %d pps" % (cnt / (time.time() - start)) )
github mike01 / pypacker / tests / test-perf.py View on Github external
"""
pypacker: 14915.2445937 pps
pypacker (manual): 15494.3632903 pps
impacket: 3929.30572776 pps
openbsd.packet: 1503.7928579 pps
scapy: 348.449269721 pps
xstruct: 88314.8953732 pps
"""
    src = dnet.addr('1.2.3.4').ip
    dst = dnet.addr('5.6.7.8').ip
    data = 'hello world'

    start = time.time()
    for i in range(cnt):
        dnet.ip_checksum(
            str(pypacker.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP,
                         len = dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN + len(data),
                         data=pypacker.udp.UDP(sport=111, dport=222,
                                       ulen=dnet.UDP_HDR_LEN + len(data),
                                       data=data))))
    print("pypacker: %s pps" % (cnt / (time.time() - start)) )
    
    start = time.time()
    for i in range(cnt):
        dnet.ip_checksum(str(pypacker.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP,
                                     len=dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN +
                                     len(data))) +
                         str(pypacker.udp.UDP(sport=111, dport=222,
                                      ulen=dnet.UDP_HDR_LEN + len(data))) +
                         data)
    print("pypacker (manual): %d pps" % (cnt / (time.time() - start)) )
github mike01 / pypacker / tests / test-perf.py View on Github external
dst = dnet.addr('5.6.7.8').ip
    data = 'hello world'

    start = time.time()
    for i in range(cnt):
        dnet.ip_checksum(
            str(pypacker.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP,
                         len = dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN + len(data),
                         data=pypacker.udp.UDP(sport=111, dport=222,
                                       ulen=dnet.UDP_HDR_LEN + len(data),
                                       data=data))))
    print("pypacker: %s pps" % (cnt / (time.time() - start)) )
    
    start = time.time()
    for i in range(cnt):
        dnet.ip_checksum(str(pypacker.ip.IP(src=src, dst=dst, p=dnet.IP_PROTO_UDP,
                                     len=dnet.IP_HDR_LEN + dnet.UDP_HDR_LEN +
                                     len(data))) +
                         str(pypacker.udp.UDP(sport=111, dport=222,
                                      ulen=dnet.UDP_HDR_LEN + len(data))) +
                         data)
    print("pypacker (manual): %d pps" % (cnt / (time.time() - start)) )
    
    start = time.time()
    for i in range(cnt):
        ip = ImpactPacket.IP()
        ip.set_ip_src('1.2.3.4')
        ip.set_ip_dst('5.6.7.8')
        udp = ImpactPacket.UDP()
        udp.set_uh_sport(111)
        udp.set_uh_dport(222)
        udp.contains(ImpactPacket.Data(data))
github mike01 / pypacker / tests / test-perf2.py View on Github external
def test_unpack(self):
        buf = str(pypacker.ip.IP())
        for i in range(self.rounds):
            pypacker.ip.IP(buf)
        print("unpack:", end=' ')
github mike01 / pypacker / tests / test-perf2.py View on Github external
def test_unpack(self):
        buf = str(pypacker.ip.IP())
        for i in range(self.rounds):
            pypacker.ip.IP(buf)
        print("unpack:", end=' ')
github mike01 / pypacker / tests / old / test_perf_old.py View on Github external
def compare_parse(cnt):
    """
pypacker: 23347.462887 pps
impacket: 9937.75963595 pps
openbsd.packet: 6826.5955563 pps
scapy: 1461.74727127 pps
xstruct: 206100.202449 pps
"""
    s = 'E\x00\x00T\xc2\xf3\x00\x00\xff\x01\xe2\x18\n\x00\x01\x92\n\x00\x01\x0b\x08\x00\xfc\x11:g\x00\x00A,\xc66\x00\x0e\xcf\x12\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"#$%&\'()*+,-./01234567'

    start = time.time()
    for i in range(cnt):
        pypacker.ip.IP(s)
    print("pypacker: %d pps" % (cnt / (time.time() - start)) )
    
    decoder = ImpactDecoder.IPDecoder()
    start = time.time()
    for i in range(cnt):
        decoder.decode(s)
    print("impacket: %d pps" % (cnt / (time.time() - start)) )

    start = time.time()
    for i in range(cnt):
        packet.Packet(packet.IP, s)
    print("openbsd.packet: %d pps" % (cnt / (time.time() - start)) )

    start = time.time()
    for i in range(cnt):
        scapy.IP(s)
github mike01 / pypacker / tests / test-perf.py View on Github external
def compare_parse(cnt):
    """
pypacker: 23347.462887 pps
impacket: 9937.75963595 pps
openbsd.packet: 6826.5955563 pps
scapy: 1461.74727127 pps
xstruct: 206100.202449 pps
"""
    s = 'E\x00\x00T\xc2\xf3\x00\x00\xff\x01\xe2\x18\n\x00\x01\x92\n\x00\x01\x0b\x08\x00\xfc\x11:g\x00\x00A,\xc66\x00\x0e\xcf\x12\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f!"#$%&\'()*+,-./01234567'

    start = time.time()
    for i in range(cnt):
        pypacker.ip.IP(s)
    print("pypacker: %d pps" % (cnt / (time.time() - start)) )
    
    decoder = ImpactDecoder.IPDecoder()
    start = time.time()
    for i in range(cnt):
        decoder.decode(s)
    print("impacket: %d pps" % (cnt / (time.time() - start)) )

    start = time.time()
    for i in range(cnt):
        packet.Packet(packet.IP, s)
    print("openbsd.packet: %d pps" % (cnt / (time.time() - start)) )

    start = time.time()
    for i in range(cnt):
        scapy.IP(s)
github mike01 / pypacker / examples / old / ping.py View on Github external
def print_reply(self, opts, buf, rtt):
        ip = pypacker.ip.IP(buf)
        if sys.platform == 'darwin':
            # XXX - work around raw socket bug on MacOS X
            ip.data = ip.icmp = pypacker.icmp.ICMP(buf[20:])
            ip.len = len(ip.data)
        print('%d bytes from %s: icmp_seq=%d ip_id=%d ttl=%d time=%.3f ms' % \
              (len(ip.icmp), opts.ip, ip.icmp.echo.seq, ip.id, ip.ttl,
               rtt * 1000))
github mike01 / pypacker / examples / dhcprequest.py View on Github external
(dhcp.DHCP_OPT_ROUTER, ''),
            (dhcp.DHCP_OPT_NETMASK, ''),
            (dhcp.DHCP_OPT_DNS_SVRS, '')
        )
    )

# build udp packet
u = udp.UDP(
        dport = 67,
        sport = 68,
        data = d
    )
u.ulen = len(u)

# build ip packet
i = ip.IP(
        dst = dnet.ip_aton('255.255.255.255'),
        src = intf.get(sysintf)['addr'].ip,
        data = u,
        p = ip.IP_PROTO_UDP
    )
i.len = len(i)

# build ethernet frame
e = ethernet.Ethernet(
        dst = dnet.ETH_ADDR_BROADCAST,
        src = hw.get(),
        data = i
    )

# send the data out
hw.send(str(e))