mirror of
https://github.com/dragonlock2/matthewtran.com.git
synced 2025-10-11 20:17:54 +00:00
update ip script
This commit is contained in:
parent
282c54a540
commit
8dc472a9c8
@ -11,13 +11,18 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
old_ipv4, old_ipv6 = None, None
|
old_ipv4, old_ipv6 = None, None
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
ipv4 = urllib.request.urlopen('https://v4.ident.me').read().decode('utf8')
|
ipv4 = urllib.request.urlopen('https://v4.ident.me').read().decode('utf8')
|
||||||
# ipv6 = urllib.request.urlopen('https://v6.ident.me').read().decode('utf8')
|
# ipv6 = urllib.request.urlopen('https://v6.ident.me').read().decode('utf8')
|
||||||
ipv6 = None
|
ipv6 = None
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
time.sleep(60)
|
||||||
|
continue
|
||||||
|
|
||||||
if ipv4 != old_ipv4 or ipv6 != old_ipv6:
|
if ipv4 != old_ipv4 or ipv6 != old_ipv6:
|
||||||
msg = Mail(
|
msg = Mail(
|
||||||
from_email='matthewlamtran@berkeley.edu',
|
from_email='mtran319@gmail.com',
|
||||||
to_emails='mtran319@gmail.com',
|
to_emails='mtran319@gmail.com',
|
||||||
subject='pls update ip',
|
subject='pls update ip',
|
||||||
html_content=f'<p>ipv4: {ipv4}</p><p>ipv6: {ipv6}</p>'
|
html_content=f'<p>ipv4: {ipv4}</p><p>ipv6: {ipv6}</p>'
|
||||||
@ -26,8 +31,10 @@ if __name__ == '__main__':
|
|||||||
print(f'IP changed to {ipv4} and {ipv6}')
|
print(f'IP changed to {ipv4} and {ipv6}')
|
||||||
resp = sg.send(msg)
|
resp = sg.send(msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e.message)
|
print(e)
|
||||||
sg = SendGridAPIClient(Path('sendgrid.key').read_text())
|
sg = SendGridAPIClient(Path('sendgrid.key').read_text())
|
||||||
|
time.sleep(60)
|
||||||
|
continue
|
||||||
|
|
||||||
old_ipv4, old_ipv6 = ipv4, ipv6
|
old_ipv4, old_ipv6 = ipv4, ipv6
|
||||||
time.sleep(60 * 60) # 60 min
|
time.sleep(3600)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user