Monitor Local IP¶
Many time it is require to track change in IP.
I have wrote this piece to help me track my home IP.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Spyder Editor
This temporary script file is located here:
/home/k2patel/bin/sendip
"""
import urllib2
import smtplib
# CUSTOMIZATION START
# Define your current IP here.
currentIP = "71.167.42.203"
# Define you email id to notify
toaddrs = "[email protected]"
# Define Source Email ID
fromaddr = "[email protected]"
# CUSTOMIZATION END
url = 'http://ip.k2patel.in'
req = urllib2.Request(url)
res = urllib2.urlopen(req)
newIP = res.read()
#print newIP.rstrip()
#print currentIP.rstrip()
if currentIP.rstrip() == newIP.rstrip():
print "All OK"
else:
msg = str("your new IP is " + newIP.rstrip())
server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()