Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import socket
  2. import smtplib
  3. from email.mime.text import MIMEText
  4. from email.header import Header
  5. import time
  6.  
  7.  
  8. def get_host_ip():
  9. try:
  10. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  11. s.connect(('172.16.54.2', 80))
  12. ip = s.getsockname()[0]
  13.  
  14. finally:
  15. s.close()
  16.  
  17. return ip
  18.  
  19.  
  20. while True:
  21. if __name__ == '__main__':
  22. ip = get_host_ip()
  23. print (ip)
  24. hostName = socket.gethostname()
  25. print (hostName)
  26. sender = '17601032000@163.com'
  27. receiver = ['dongliang@ceri.com.cn']
  28. s1 = '''I'm Dong Liang.'''
  29. s2 = '''I'm sending this email to get'''
  30. s3 = ''' the network information of this PC.'''
  31. sa = s1 + s2 + s3
  32. content = sa + 'This PC is: ' + hostName + ' ,and its IP is: ' + ip
  33. print (content)
  34. msg = MIMEText(content)
  35. msg['From'] = Header("17601032000@163.com")
  36. msg['To'] = Header("dongliang@ceri.com.cn")
  37. msg['Subject'] = Header('the network information of ' + hostName)
  38. smtp = smtplib.SMTP_SSL("smtp.163.com",465)
  39. smtp.login('17601032000', 'passw0rd')
  40. smtp.sendmail(sender, receiver, msg.as_string())
  41. print "send OK!"
  42. smtp.quit()
  43.  
  44. time.sleep(86400)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement