help on request

-2

I'm writing a subdomain scan and I made the following code (sorry to make you cry with it):

import requests
while True:
 url = raw_input("url: ")
 lista = ['blog', 'ftp', 'cpanel', 'intranet']
 for list in lista:
     url2 = url.replace("www", list)
     req = requests.get(url2)
     if req == True:
        print ("Ok " + url2)
     else:
        print ("Nop" + url2)

Could you tell me where the error is and how to fix it? Thanks

    
asked by anonymous 18.06.2018 / 04:21

1 answer

0

Looking at your code, I think you want something like this:

import requests
while True:
    url = input("url: ")
    lista = ['blog', 'ftp', 'cpanel', 'intranet']
    for list in lista:
        url2 = url.replace("www", list)
        try:
            req = requests.get('http://{}'.format(url2))
        except:
            print("Erro", url2)
            continue
        if req.status_code == requests.codes.ok:
            print("Ok", url2)
        else:
            print("NOK", url2)

Where the changes I made were:

  • Add " link " to request
  • Add a structure " try except " to catch connection errors (domain not found, for example)
  • Use the status_code in the requisition success test, where, roughly speaking, failure means not found domain, but something like page not found.
18.06.2018 / 17:27