python http status code

前端 未结 2 1230
醉话见心
醉话见心 2021-01-25 01:23

I\'m writing my own directory buster in python, and I\'m testing it against a web server of mine in a safe and secure environment. This script basically tries to retrieve common

相关标签:
2条回答
  • 2021-01-25 01:45

    I would be adviced you to use http://docs.python-requests.org/en/latest/# for http.

    0 讨论(0)
  • 2021-01-25 01:53

    I did not found any problems with your code, except it is almost unreadable. I have rewritten it into this working snippet:

    import httplib
    
    host = 'www.google.com'
    directories = ['aosicdjqwe0cd9qwe0d9q2we', 'reader', 'news']
    
    for directory in directories:
        conn = httplib.HTTPConnection(host)
        conn.request('HEAD', '/' + directory)
    
        url = 'http://{0}/{1}'.format(host, directory)
        print '    Trying: {0}'.format(url)
    
        response = conn.getresponse()
        print '    Got: ', response.status, response.reason
    
        conn.close()
    
        if response.status == 200:
            print ("[!] The subdirectory '{0}' "
                   "could be interesting.").format(directory)
    

    Outputs:

    $ python snippet.py
        Trying: http://www.google.com/aosicdjqwe0cd9qwe0d9q2we
        Got:  404 Not Found
        Trying: http://www.google.com/reader
        Got:  302 Moved Temporarily
        Trying: http://www.google.com/news
        Got:  200 OK
    [!] The subdirectory 'news' could be interesting.
    

    Also, I did use HEAD HTTP request instead of GET, as it is more efficient if you do not need the contents and you are interested only in the status code.

    0 讨论(0)
提交回复
热议问题