Created
July 7, 2015 06:21
-
-
Save netmarkjp/bebc5cee6a63a084ab66 to your computer and use it in GitHub Desktop.
dns query example with scapy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from datetime import datetime | |
from scapy.all import DNS | |
from scapy.all import DNSQR | |
from scapy.all import IP | |
from scapy.all import UDP | |
from scapy.all import send | |
import multiprocessing as mp | |
import sys | |
COUNT = int(sys.argv[1]) | |
PROCS = int(sys.argv[2]) | |
def sendPacket(): | |
packet = IP(dst="127.0.0.1") / UDP() / DNS(qd=DNSQR( | |
qname="localhost", qtype="A")) | |
send(packet, count=COUNT, verbose=False) | |
def main(): | |
ps = [mp.Process(target=sendPacket) for i in xrange(0, PROCS)] | |
time1 = datetime.now() | |
print time1 | |
for p in ps: | |
p.start() | |
for p in ps: | |
p.join() | |
time2 = datetime.now() | |
print len(ps), "x", COUNT, "=", len(ps) * COUNT, "packets.", | |
print time2 - time1, | |
print len(ps) * COUNT / (time2 - time1).seconds, "qps" | |
if __name__ == "__main__": | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bvuntu% sudo python myexample.py 1000 1 2>/dev/null | |
2015-07-07 15:06:21.386702 | |
1 x 1000 = 1000 packets. 0:00:09.536814 111 qps | |
bvuntu% sudo python myexample.py 1000 2 2>/dev/null | |
2015-07-07 15:06:34.176933 | |
2 x 1000 = 2000 packets. 0:00:15.062760 133 qps | |
bvuntu% sudo python myexample.py 1000 3 2>/dev/null | |
2015-07-07 15:06:58.848696 | |
3 x 1000 = 3000 packets. 0:00:17.410881 176 qps | |
bvuntu% sudo python myexample.py 1000 4 2>/dev/null | |
2015-07-07 15:07:27.936026 | |
4 x 1000 = 4000 packets. 0:00:17.823769 235 qps | |
bvuntu% sudo python myexample.py 1000 30 2>/dev/null | |
2015-07-07 15:07:50.223700 | |
30 x 1000 = 30000 packets. 0:00:30.852318 1000 qps | |
bvuntu% sudo python myexample.py 1000 60 2>/dev/null | |
2015-07-07 15:08:27.892227 | |
60 x 1000 = 60000 packets. 0:00:53.811380 1132 qps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bvuntu% ./dnsperf -s 127.0.0.1 -d /tmp/list -l 10 | |
DNS Performance Testing Tool | |
Nominum Version 2.0.0.0 | |
[Status] Command line: dnsperf -s 127.0.0.1 -d /tmp/list -l 10 | |
[Status] Sending queries (to 127.0.0.1) | |
[Status] Started at: Tue Jul 7 14:34:27 2015 | |
[Status] Stopping after 10.000000 seconds | |
[Status] Testing complete (time limit) | |
Statistics: | |
Queries sent: 1023468 | |
Queries completed: 1023468 (100.00%) | |
Queries lost: 0 (0.00%) | |
Response codes: NOERROR 1023468 (100.00%) | |
Average packet size: request 27, response 43 | |
Run time (s): 10.000046 | |
Queries per second: 102346.329207 | |
Average Latency (s): 0.000281 (min 0.000000, max 0.015195) | |
Latency StdDev (s): 0.000412 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment