Added more verbose output so I know more about what I am looking at when doing the queries as I had forgotten what some of my output meant. I also added a lot of comments so I can remember more of what the things I wrote do. After reading about how source code should be its own documentation, I decided I need to be more verbose with my comments.
This commit is contained in:
parent
ac8980c614
commit
eef67db7a6
33
ip-api.py
33
ip-api.py
@ -20,11 +20,13 @@ def query_api(host):
|
|||||||
print('\nThe IP "{}" is {}'.format(x, json_data['message']))
|
print('\nThe IP "{}" is {}'.format(x, json_data['message']))
|
||||||
# Print out wanted JSON data formatted nicely
|
# Print out wanted JSON data formatted nicely
|
||||||
else:
|
else:
|
||||||
print('\nCity\State: {}, {}\n'
|
print('\nAS: {}\n'
|
||||||
|
'City\State: {}, {}\n'
|
||||||
'Country: {}\n'
|
'Country: {}\n'
|
||||||
'ISP: {}\n'
|
'ISP: {}\n'
|
||||||
'IP: {}\n'
|
'IP: {}\n'
|
||||||
'MX: {}'.format(
|
'MX: {}'.format(
|
||||||
|
json_data['as'],
|
||||||
json_data['city'],
|
json_data['city'],
|
||||||
json_data['regionName'],
|
json_data['regionName'],
|
||||||
json_data['country'],
|
json_data['country'],
|
||||||
@ -52,28 +54,43 @@ def findMX(host):
|
|||||||
# append terminal output to variable std_out
|
# append terminal output to variable std_out
|
||||||
for line in p:
|
for line in p:
|
||||||
if re.search('not found', line):
|
if re.search('not found', line):
|
||||||
|
print('No MX record found querying ' + host)
|
||||||
query_api([host])
|
query_api([host])
|
||||||
break
|
break
|
||||||
# Checs to see if 'domain name pointer' is in the line and finds the ip
|
# Checks to see if 'domain name pointer' is in the line and finds the
|
||||||
# associated with the pointer to do a query on. Created for IPs that do
|
# ip associated with the pointer to do a query on. Created for IPs that
|
||||||
# not have a easily parsed MX record return.
|
# do not have a easily parsed MX record return.
|
||||||
elif re.search('domain name pointer', line):
|
elif re.search('domain name pointer', line):
|
||||||
|
print(line)
|
||||||
|
print('Domain name pointer found querying original host: ' + host)
|
||||||
query_api([host])
|
query_api([host])
|
||||||
extra = re.search('.in-addr.arpa .*', str(line))
|
extra = re.search('.in-addr.arpa .*', str(line))
|
||||||
thing = line.replace(extra.group(0), '')
|
thing = line.replace(extra.group(0), '')
|
||||||
|
print('\nDomain Name pointer Query: ' + thing)
|
||||||
query_api([thing.rstrip()])
|
query_api([thing.rstrip()])
|
||||||
break
|
break
|
||||||
std_out.append(line)
|
std_out.append(line)
|
||||||
p.close
|
p.close
|
||||||
|
|
||||||
# create iterator
|
|
||||||
i = 0
|
|
||||||
# split line into dict and return MX servers
|
# split line into dict and return MX servers
|
||||||
for x in std_out:
|
for x in std_out:
|
||||||
split = std_out[i].split()
|
# When using os.popen it basically acts like a terminal allowing you to
|
||||||
|
# run terminal commands from your Python script and use its output. We
|
||||||
|
# are using as an example 'host -t MX google.com' the output would look
|
||||||
|
# like:
|
||||||
|
# google.com mail is handled by 30 alt2.aspmx.l.google.com
|
||||||
|
# google.com mail is handled by 40 alt3.aspmx.l.google.com
|
||||||
|
# google.com mail is handled by 10 aspmx.l.google.com
|
||||||
|
# google.com mail is handled by 20 alt1.aspmx.l.google.com
|
||||||
|
# google.com mail is handled by 50 alt4.aspmx.l.google.com
|
||||||
|
split = std_out[x].split()
|
||||||
|
# We use .split() method to split the std_out list entry by spaces
|
||||||
|
|
||||||
MXServer.append(split[-1])
|
MXServer.append(split[-1])
|
||||||
i = i + 1
|
# We take the last item in the split(aspmx.l.google.com) and append it
|
||||||
|
# to the list 'MXServer'
|
||||||
query_api(MXServer)
|
query_api(MXServer)
|
||||||
|
# Now we send the list 'MXServer' to the query_api function
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user