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.

42 lines
987 B

  1. import json
  2. import requests
  3. import os
  4. def search():
  5. main_api = 'http://ip-api.com/json/'
  6. ip = findMX()
  7. for host in ip:
  8. json_data = requests.get(main_api + host).json()
  9. print('\nCity\State: {}, {}\n Country: {}\n ISP: {}\n IP: {}\n MX: {}'.format(
  10. json_data['city'],
  11. json_data['regionName'],
  12. json_data['country'],
  13. json_data['isp'],
  14. json_data['query'],
  15. host))
  16. def findMX():
  17. host = input("Who do you want to look up?: ")
  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. search()