You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

  1. import argparse
  2. import json
  3. import requests
  4. import os
  5. def search(host):
  6. main_api = 'http://ip-api.com/json/'
  7. ip = findMX(host)
  8. for host in ip:
  9. json_data = requests.get(main_api + host).json()
  10. print('\nCity\State: {}, {}\n Country: {}\n ISP: {}\n IP: {}\n MX: {}'.format(
  11. json_data['city'],
  12. json_data['regionName'],
  13. json_data['country'],
  14. json_data['isp'],
  15. json_data['query'],
  16. host))
  17. def findMX(host):
  18. p = os.popen('host -t MX ' + host)
  19. #initialize dicts
  20. std_out = []
  21. split = []
  22. MXServer = []
  23. #append terminal output to variable std_out
  24. for line in p:
  25. std_out.append(line)
  26. p.close
  27. #create iterator
  28. i = 0
  29. #split line into dict and return MX servers
  30. for x in std_out:
  31. split = std_out[i].split()
  32. MXServer.append(split[6])
  33. i = i + 1
  34. return MXServer
  35. if __name__ == "__main__":
  36. parser = argparse.ArgumentParser()
  37. parser.add_argument("host", help="hostname to lookip")
  38. args = parser.parse_args()
  39. search(args.host)