Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import smtplib
- from email.mime.text import MIMEText
- from email.header import Header
- import time
- def get_host_ip():
- try:
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- s.connect(('172.16.54.2', 80))
- ip = s.getsockname()[0]
- finally:
- s.close()
- return ip
- while True:
- if __name__ == '__main__':
- ip = get_host_ip()
- print (ip)
- hostName = socket.gethostname()
- print (hostName)
- sender = '17601032000@163.com'
- receiver = ['dongliang@ceri.com.cn']
- s1 = '''I'm Dong Liang.'''
- s2 = '''I'm sending this email to get'''
- s3 = ''' the network information of this PC.'''
- sa = s1 + s2 + s3
- content = sa + 'This PC is: ' + hostName + ' ,and its IP is: ' + ip
- print (content)
- msg = MIMEText(content)
- msg['From'] = Header("17601032000@163.com")
- msg['To'] = Header("dongliang@ceri.com.cn")
- msg['Subject'] = Header('the network information of ' + hostName)
- smtp = smtplib.SMTP_SSL("smtp.163.com",465)
- smtp.login('17601032000', 'passw0rd')
- smtp.sendmail(sender, receiver, msg.as_string())
- print "send OK!"
- smtp.quit()
- time.sleep(86400)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement