Guest User

Untitled

a guest
Jan 22nd, 2018
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import socket
  3. from datetime import datetime
  4. import smtplib
  5. from email.MIMEMultipart import MIMEMultipart
  6. from email.MIMEText import MIMEText
  7.  
  8.  
  9. def sendMail(subject, text):
  10. gmailUser = 'mail@ideabay.kr'
  11. gmailPassword = '(CHANGE)'
  12. recipient = 'gofeel@gmail.com'
  13. msg = MIMEMultipart()
  14. msg['From'] = gmailUser
  15. msg['To'] = recipient
  16. msg['Subject'] = subject
  17. msg.attach(MIMEText(text))
  18. mailServer = smtplib.SMTP('smtp.gmail.com', 587)
  19. mailServer.ehlo()
  20. mailServer.starttls()
  21. mailServer.ehlo()
  22. mailServer.login(gmailUser, gmailPassword)
  23. mailServer.sendmail(gmailUser, recipient, msg.as_string())
  24. mailServer.close()
  25. print('Sent email to %s' % recipient)
  26.  
  27.  
  28. #Simply change the host and port values
  29. host = 'zzid.net'
  30. port = 80
  31. dt = datetime.now()
  32.  
  33. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  34. s.settimeout(15.0)
  35. try:
  36. s.connect((host, port))
  37. s.shutdown(2)
  38. text = "Success connecting to "
  39. text = text + host + " on port: " + str(port)
  40. text = text + dt.strftime(" %A, %d. %B %Y %I:%M%p")
  41. sendMail("Success connecting to " + host, text);
  42. except:
  43. dt = datetime.now()
  44. text = "Cannot connect to "
  45. text = text + host + " on port: " + str(port)
  46. text = text + dt.strftime(" %A, %d. %B %Y %I:%M%p")
  47. sendMail("Can't connect to " + host, text);
Add Comment
Please, Sign In to add comment