-
Notifications
You must be signed in to change notification settings - Fork 1
/
broadcast IP
40 lines (30 loc) · 979 Bytes
/
broadcast IP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import smtplib
from email.mime.text import MIMEText
from requests import get
import urllib
def wait_until_network():
while True:
try:
response = urllib.request.urlopen('https://api.ipify.org',timeout = 1)
print("Connected!")
return
except:
print("Could not connect.")
pass
def send_email():
ip = get('https://api.ipify.org').content.decode('utf8')
print('My public IP address is: {}'.format(ip))
sender = '[email protected]'
receiver = '[email protected]'
msg = MIMEText('Ooo heloo new IP who dis?')
msg['Subject'] = ip
msg['From'] = 'NabDog'
msg['To'] = 'Matos Patos'
user = '2db52f673b38b0'
password = '388abc115e91a2'
with smtplib.SMTP("smtp.mailtrap.io", 2525) as server:
server.login(user, password)
server.sendmail(sender, receiver, msg.as_string())
print("mail successfully sent")
wait_until_network()
send_email()