0

More specifically my function grabs all the domains in a my database table and returns them. I want to know how to input these domains into another function that will run the Kali Linux tool URLcrazy for each of the domains in that table.

For example my function that outputs these:

google.com
yahoo.com
Here is the function:

def grab_domains():
    try:
        db = pymysql.connect(host="localhost",
                         user="root", passwd="root",
                         db="typosquat")
except ConnectionAbortedError as e:
    print(e, "\n")

temp = ""
cursor = db.cursor()
cursor.execute('SELECT name From domains')
for rows in cursor.fetchall():
    for entries in rows:
        temp += entries
        domains = entries[0:]
        print(domains)

return temp

Here is the output:

google.com
yahoo.com

How do I write another function that will run the script URLcrazy on each of these domains? Assuming all scripts are in same file location.

This is all I have I cant figure out how to run it for each domain, only know how to for a single output.

def run_urlcrazy():
    np = os.system("urlcrazy " + grab_domains())
    print(np)
    return np

How to I get this function to run URLcrazy for each domain?^^

This is my first post ever on stack overflow let me know what I can do to improve it and help me with question if possible! Thanks

1
  • to put it simply, why dont you write the output from the first function to a file and read the file from your second script? Commented Jul 7, 2017 at 18:03

1 Answer 1

2

You'll need a loop:

def run_urlcrazy():
    ret_vals = []
    for domain in grab_domains():
        np = os.system("urlcrazy " + domain)
        ret_vals.append(np)
    return ret_vals

I recommend a for loop because it can efficiently iterate over whatever your function returns.


You'll need to make a minor modification to your grab_domains() function as well:

temp = []
cursor = db.cursor()
cursor.execute('SELECT name From domains')
for rows in cursor.fetchall():
    for entries in rows:
        domains = entries[0:]
        temp.extend(domains)

return temp

Now, your function returns a list of domains. You can iterate over this.

Sign up to request clarification or add additional context in comments.

4 Comments

grab_domains() is returning just a single domain right?
@pyjg I've proposed a modification. It seems OP is concatenating it in a string.
Yes that was the problem, was concatenating with string. Thank you!
Thank you, and glad I could help. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.