document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/python3
  2. # import argparse library to handle and parse user input.
  3. import argparse
  4. # import requests library to handle http requests.
  5. import requests
  6.  
  7. def get_headers(infile):
  8. # get_headers will attempt to make a request to each url and return results
  9. header_info = []
  10. for url in infile:
  11. http_req = None
  12. # attempt to make a connection if not add the error to the list.
  13. if not url:
  14. continue
  15. try:
  16. http_req = requests.get(url.strip())
  17. except Exception as error:
  18. header_info.append('################################')
  19. header_info.append("error: {0}".format(error))
  20. header_info.append('################################')
  21.  
  22. # if no results next url else add information to list.
  23. if not http_req:
  24. continue
  25. # format the information for human readablity.
  26. header_info.append('--------------------------------')
  27. header_info.append(url.strip())
  28. for items in http_req.headers:
  29. header_info.append('{0}: {1}'.format(items, http_req.headers[items]))
  30. #close out connect before making the next.
  31. http_req.close()
  32.  
  33. # return the information gathered.
  34. return header_info
  35.  
  36. # check to see the script is being ran independently, if so run the parser for user input.
  37. if __name__ == '__main__':
  38. # set up argument parser and define inputs.
  39. parser = argparse.ArgumentParser(description='simple banner grabber')
  40. parser.add_argument('-i', '--input_file', type=argparse.FileType('r'), help='The file containing urls to requests headers from', required=True)
  41. parser.add_argument('-o', '--output_file', help='The file to save the results to')
  42. # get user input.
  43. args = parser.parse_args()
  44.  
  45. # get the headers utilzing the get_headers function.
  46. headers = get_headers(args.input_file)
  47.  
  48. # display the output
  49. for lines in headers:
  50. print(lines)
  51.  
  52. # check to see if the user wanted the data saved and do it
  53. if args.output_file:
  54. with open(args.output_file, "w") as savefile:
  55. for lines in headers:
  56. savefile.write(lines)
  57. print('################################')
  58. print("Saved out put to {0}".format(args.output_file))
');