From 6805f153d224ba2bb10ab43b5a572300ff34ee22 Mon Sep 17 00:00:00 2001 From: Michael Heidelberger Date: Fri, 23 Mar 2018 10:48:17 -0500 Subject: [PATCH] Working MX Lookup Script using free online api 150 calls per day max --- ip-api.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ip-api.py diff --git a/ip-api.py b/ip-api.py new file mode 100644 index 0000000..048b16d --- /dev/null +++ b/ip-api.py @@ -0,0 +1,42 @@ +import json +import requests +import os + +def search(): + main_api = 'http://ip-api.com/json/' + + ip = findMX() + for host in ip: + json_data = requests.get(main_api + host).json() + + print('\nCity\State: {}, {}\n Country: {}\n ISP: {}\n IP: {}\n MX: {}'.format( + json_data['city'], + json_data['regionName'], + json_data['country'], + json_data['isp'], + json_data['query'], + host)) + +def findMX(): + host = input("Who do you want to look up?: ") + p = os.popen('host -t MX ' + host) + + #initialize dicts + std_out = [] + split = [] + MXServer = [] + + #append terminal output to variable std_out + for line in p: + std_out.append(line) + p.close + + #create iterator + i = 0 + #split line into dict and return MX servers + for x in std_out: + split = std_out[i].split() + MXServer.append(split[6]) + i = i + 1 + return MXServer +search()