Skip to content

Commit

Permalink
Introduce domain,ip andtimestamp logging in log.cv
Browse files Browse the repository at this point in the history
  • Loading branch information
saidbakr committed Feb 27, 2020
1 parent 1bb0abd commit 7b8bdb6
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions freemyip.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from urllib.request import urlopen
import csv
import re
import time
# Configurations values
base_url = 'https://freemyip.com/update'
tokens_file = 'tokens.csv'
log_file = 'log.csv'
# End of Configurations
data = {}
log_data = {}
ip = ''

def load_tokens(tokens_file):
Expand All @@ -22,7 +25,7 @@ def extract_ip(msg):
pattern = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
return re.search(pattern,msg).group()

def check_url(url):
def check_url(url,domain = None):
global ip
try:
output = urlopen(url)
Expand All @@ -32,12 +35,33 @@ def check_url(url):
msg = output.read().decode('utf-8')
if "ERROR" in msg:
ip = ''
prep_log({domain:[ip,time.time()]})
return False
else:
ip = extract_ip(msg)
ip = extract_ip(msg)
prep_log({domain:[ip,time.time()]})
return True
def prep_log(l):
global log_data
log_data.update(l)


def create_log(log_file):
try:
f = open(log_file,'w+')
except IOError:
print('The log file could not be written!')

for domain,i in log_data.items():
#print(i[1],domain)
f.write(domain+','+i[0]+','+str(i[1])+'\n')

f.close()


load_tokens(tokens_file)
print('Domain'+'\t\t\t'+'Status'+'\t'+'IP')
for domain,token in data.items():
print(domain,'\t',check_url(create_url(domain, token)),'\t', ip)
print(domain,'\t',check_url(create_url(domain, token),domain),'\t', ip)

create_log(log_file)

0 comments on commit 7b8bdb6

Please sign in to comment.