• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0-only
2# This file is part of Scapy
3# See https://scapy.net/ for more information
4# Copyright (C) Guillaume Valadon
5
6from common import *
7import time
8
9N = 10000
10raw_packet = b'E\x00\x00(\x00\x01\x00\x00@\x11|\xc2\x7f\x00\x00\x01\x7f\x00\x00\x01\x005\x005\x00\x14\x00Z\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00'
11
12start = time.time()
13for i in range(N):
14    p = IP(dst="127.0.0.1", src="127.0.0.1") / UDP() / DNS()
15    assert raw(p) == raw_packet
16print("Build - %.2fs" % (time.time() - start))
17
18start = time.time()
19for i in range(N):
20    p = IP(raw_packet)
21    assert DNS in p
22print("Dissect - %.2fs" % (time.time() - start))
23
24start = time.time()
25for i in range(N):
26    p = IP(dst="127.0.0.1", src="127.0.0.1") / UDP() / DNS()
27    s = raw(p)
28    assert s == raw_packet
29    p = IP(s)
30    assert DNS in p
31print("Build & dissect - %.2fs" % (time.time() - start))
32