#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Spyder Editor

This temporary script file is located here:
/home/k2patel/bin/sendip
"""

import urllib3
import smtplib
import certifi


# CUSTOMIZATION START

# Define your current IP here.
currentIP = "35.237.176.83"
# Define you email id to notify
toaddrs = "k2patel@gmail.com"
# Define Source Email ID
fromaddr = "k2patel@k2patel.in"


# CUSTOMIZATION END

url = 'https://ipv4.icanhazip.com'
http = urllib3.PoolManager(ca_certs=certifi.where())
req = http.request('GET', url)
newIP = req.data.decode('utf-8').rstrip()

#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()
