• 树莓派获取ip地址发送到邮箱


    公网 ip.sh
    
    curl http://members.3322.org/dyndns/getip >>/email/ip.log

    python /email/mail.py

    #######--->>>from :http://www.cnblogs.com/xiaobo-Linux/p/8672496.html
    #!usrinenv python  
    #encoding: utf-8  
    import web  
    def send_mail(send_to, subject, body, cc=None, bcc=None):  
        try:  
            web.config.smtp_server = 'smtp.163.com'   
            web.config.smtp_port = 25    
            web.config.smtp_username = 'zhao'   
            web.config.smtp_password = '邮箱第三方验证码'   
            web.config.smtp_starttls = True  
            send_from = 'zhao@163.com'   
            
            web.sendmail(send_from, send_to, subject, body, cc=cc, bcc=bcc)  
            return 1   
        except Exception, e:  
            print e  
            return -1 #fail  
    if __name__=='__main__':  
        f=file('/email/ip.log') 
        f1=f.read()
        f.close()
        send_to = ['zhao@qq.com']          
        subject = 'connection check'  
        body = 'hello ,  I am still alive. I will send you my public ip is',f1  
        send_mail(send_to, subject, body)

      

    import web 
    安装web.py如下
    wget http://webpy.org/static/web.py-0.37.tar.gz
     tar -xf web.py-0.37.tar.gz 
    sudo python setup.py install
    sudo nano /etc/rc.local
    
    
    python /email/mail.py
    
    
    

    crontab -e 开始配置
    
    
    在最后一行输入 每天6点发送IP地址

    0 6 * * * sh /email/ip.sh

    chmod 755 mail.py
    
    chmod 755 ip.sh
  • 相关阅读:
    是否有人会想起
    春风下也有落叶
    to kongove:呵呵~是啊,偶尔吹得玩下,仅当娱乐而已……
    木头人の狂想
    夜行静思湖
    [学习标准库]math.h
    [学习标准库]ctype.h
    [学习标准库]stdio.h
    句子
    [学习标准库]assert.h
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/8672496.html
Copyright © 2020-2023  润新知