A little python script for evaluating subdomains!

in #technology6 years ago (edited)

So today we have a little python script i wrote that helps you evaluate subdomains for a given domain. We will look at the script step by step to help you understand.

The script can be found here:

https://github.com/toslaty/steem/blob/master/eval.py

The finished script will be invoked via the following command:

python eval.py -i Datei.txt -w domain.txt -d google.com

  • i is the wordlist that shall be read
  • w is the output list to which the script will write the found subdomains to
  • d is where you enter the targeted domain (for example google.com)

So let's look at the script. First we have to import the following libraries via import(): requests and argparse

importpy.png

So what are these libraries for? Requests is a easy to use library for making http requests.
Argparse is the library responsible for creating our command line interface.

As in most cases, the main()-function is the entry point for our script. Here we first define the ArgumentParser() object (line 29) which is necessary if we want our command line arguments to be recognized.
After that we add the arguments with the add_argument() method. Here we can define things like the expected data type(by default it is read as a string) or the help to the command that shall be invoked.

mainpy.png

Now we invoke parse_args() for our parser object from line 29. It is possible to define an action for the arguments and what is to be done with them. The default action here is store so we‘ll go with it because that is enough for our purpose.
In line 36 we check if any of the options was left empty at program start. In case of being empty the program will print out its usage.

So now we are actually going to work with the specified arguments. Remember? Our goal was to take input from a given textfile and check if there is subdomain for a given domain and print that out to a new file.

We achieve this by opening the openfi() function which is defined in lines 5 to 12. This fuction takes in the given command line arguments. First we open the file which is supplied in the command line options via -i with open() in line 6. „r“ specifies that the file will be read.
Now we have a little loop that iterates through any line in our file f. After that we call the req() function.
We do this with a try except construction because if a connection cant be made an exception will be thrown. Except: continue will tell the script to ignore the exception.

openpy.png

So in the req() function we make the actual request. We define a variable that holds the string with the address to connect to. After that we make the request and check if the status code is 200.

reqpy.png

If it is, the address will be written to the .txt-file you specified when the script started. For that we define the writeto() function.

Here is the wordlist with the input we used when starting the script.

inpy.png

And here is the output in the wordlist we produced which told us that mail.google.com is a valid subdomain.

oupy.png

If you have any questions feel free to post them below.

Sort:  

Congratulations @toalsty! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 200 upvotes. Your next target is to reach 300 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

Saint Nicholas challenge for good boys and girls

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @toalsty! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got a First Reply

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Coin Marketplace

STEEM 0.22
TRX 0.21
JST 0.035
BTC 98789.27
ETH 3346.59
USDT 1.00
SBD 3.08