User Tools

Site Tools


monitor_your_ip_and_send_email_if_change

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

monitor_your_ip_and_send_email_if_change [2012/04/05 21:23] (current)
k2patel created
Line 1: Line 1:
 +====== 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.
 +
 +<code python>
 +#​!/​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()
 +
 +</​code>​
monitor_your_ip_and_send_email_if_change.txt ยท Last modified: 2012/04/05 21:23 by k2patel