#StackBounty: #python #python-3.x #multithreading Invoking parallel threads of a nslookup command in python

Bounty: 50

I’ve written below python script just to invoke parallel threads of a command nslookup linux-host01 dns-server, i’m Just trying to flood the DNS Server dns-server with multiple number of queries in parallel way.

As an argument to this script i’m passing a hostlist file example linux-host01 , linux-host02 etc.

To achieve this i’m using threading module with the below code and this works fine, However, i’m using the the threading first time hence would like to know if this can be simplified of enhanced further.

import os
import threading
from sys import argv, exit

lock = threading.Lock()

hostfile = argv[1]

lst = []
with open(hostfile, 'r') as frb:
    for line in frb:

threads = []
thread_count = len(lst)

def pop_queue():
    host = None
    if lst:
        host = lst.pop()
    return host

def dequeue():
    while len(lst) != 0:
        host = pop_queue()
        if not host:
            return None

def dolookup(name):
    while True:
        os.system("/usr/bin/nslookup %s dns-test01" %name)

for i in range(thread_count):
    t = threading.Thread(target=dequeue)
    print "started thread %s" %i

[t.join() for t in threads]

Appreciate any help on this.

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.