Last active
August 29, 2015 14:05
-
-
Save AlexAvlonitis/6ee908e6e5d759b18003 to your computer and use it in GitHub Desktop.
Dynamic public ip address finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Public IP finder project v1.0 by Alex Avlonitis http://alex.avlonitis.me | |
""" | |
import urllib | |
import re | |
import os | |
import smtplib | |
#######SMTP CONFIGURATION####### | |
def emails(): | |
username = "your email" | |
password = "your password" | |
fromaddr = "from email@" | |
toaddr = "to email@" | |
server = smtplib.SMTP('smtp.live.com', 587) | |
server.starttls() | |
server.login(username, password) | |
server.sendmail(fromaddr, toaddr, "the current public IP is: "+stringos) | |
server.quit() | |
appdata = os.getenv('APPDATA') | |
path = appdata+"\ips.txt" | |
url = "http://showmyip.gr" | |
print url | |
r = urllib.urlopen(url).read() | |
ip = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}", r) # it finds only the ip part from showmyip.gr | |
stringos = str(ip) | |
if not os.path.isfile(path): #if the ips.txt doesn't exist, it creates it and then it writes the ip and sends the email | |
file = open(path,"w") | |
file = open(path,"r") | |
else: | |
file = open(path,"r") #if the file already exists | |
if file.readline() == stringos: # compares the ip from the file with the website's one, if it's the same it doesn't do anything | |
file.close() | |
else: | |
file = open(path,"w") # if it's different, it overwrites the file and then sends an email | |
file.write(stringos) | |
file.close() | |
emails() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment