for ip in ip_con: #get locations of ip connections ip_loc = ip_loc + Locate.Locate(ip) + '\n' dom_loc = '' for d in ip_dom: #get locations of domain connections dom_loc = dom_loc + Locate.Locate(DomainLookup.Domain_to_IP(d)) + '\n' locations = ip_loc + '\n' + dom_loc states = Locate.FindStates(locations) #finds the states of the connections for s in states: #check to see if in approved locaitons if (s == 'RI' or s == 'NY'): continue else: return True #if there is a problem, returns true return False #otherwise returns false def CleanUp(): #deletes file generated when there is a problem os.remove('LocationReport') if(Guard()): #if there is a problem try: #open file file = open('LocationReport', 'rb+') except:#or create it file = open('LocationReport', 'wb+') results = file.read() if(results == 'We Have a Problem'): #if the problem has been delt with, ignore it print('Already Handled') #already been dealt else: #otherwise file.seek(0,0) file.write('We Have a Problem') #log the problem in the file GMail.email('From', ['to'], 'Intruder', 'We have an issue\n' + locations) #send email about the problem
import sys results = IPAddress.ExtIP() + '\n' + IPAddress.IntIP() #get the current IP Addresses now = datetime.datetime.now() #get date & time ip = re.compile("\d+\.\d+\.\d+\.\d+") #set up regular expresion for ip Address try: #try to open file containing previous IPs and read them in file = open('IPAddress.txt', 'r+') old = ip.findall(file.read()) except: #if that fails create the file and set the old ones to 0.0.0.0 file = open('IPAddress.txt', 'w') old = ['0', '0', '0'] new = ip.findall(results) #get the Ips from the formated results i = 0 needsupdate = False while (i < len(new)): #compairs current IPs to stored IPs if (new[i] == old [i]): needsupdate = False else: needsupdate = True i = i + 1 if (len(sys.argv) > 1 and sys.argv[1] == '-s'): #if '-s' force print the results print(results) elif (needsupdate or (len(sys.argv) > 1 and sys.argv[1] == '-f' )): # if there is a change or '-f' force email the results GMail.email('From', ['To'], 'IP Update', results) file.seek(0,0) file.write(str(now) + '\n' + results + '\n') file.close() #close the file
now = datetime.datetime.now() #get date & time ip = re.compile("\d+\.\d+\.\d+\.\d+") #set up regular expresion for ip Address try: #try to open file containing previous IPs and read them in file = open('IPAddress.txt', 'r+') old = ip.findall(file.read()) except: #if that fails create the file and set the old ones to 0.0.0.0 file = open('IPAddress.txt', 'w') old = ['0', '0', '0'] new = ip.findall(results) #get the Ips from the formated results i = 0 needsupdate = False while (i < len(new)): #compairs current IPs to stored IPs if (new[i] == old[i]): needsupdate = False else: needsupdate = True i = i + 1 if (len(sys.argv) > 1 and sys.argv[1] == '-s'): #if '-s' force print the results print(results) elif (needsupdate or (len(sys.argv) > 1 and sys.argv[1] == '-f')): # if there is a change or '-f' force email the results GMail.email('From', ['To'], 'IP Update', results) file.seek(0, 0) file.write(str(now) + '\n' + results + '\n') file.close() #close the file