• python随机服务器的双线出口ip发送邮件


    #-*- coding:utf-8 -*-
    import smtplib
    import sys
    import random
    import socket
    from email.mime.text import MIMEText



    true_socket = socket.socket
    def bound_socket(*a, **k):
        sock = true_socket(*a, **k)

        #随机出一个IP
        ip_list = ['XXX.XXX.XXX.XXX','XXX.XXX.XXX.XXX']
        index = random.randint(1,1000000)
        ip_index = 0
        if index>=1 and index<=500000:
            ip_index = 0
        else:
            ip_index = 1
        ip = ip_list[ip_index]
        sock.bind((ip, 0))
        return sock

    #绑定IP
    socket.socket = bound_socket


    mail_host="smtp.XXX.XXX"  #smtp
    mail_user="XXX@XXX.XXX"    #user
    mail_pass="XXX"   #pwd
    mail_postfix="XXX.com"  #发件箱的后缀

    def send_mail(to_list,sub,content):
        me="<XXX@XXX.XXX>"
        msg = MIMEText(content,_subtype='html',_charset='utf-8')
        msg["Accept-Language"]="zh-CN"
        msg["Accept-Charset"]="ISO-8859-1,utf-8"
        msg['Subject'] = sub
        msg['From'] = me
        msg['To'] = ";".join(to_list)
        try:
            server = smtplib.SMTP()
            server.connect(mail_host)
            server.login(mail_user,mail_pass)
            server.sendmail(me, to_list, msg.as_string())
            server.close()
            return True
        except Exception, e:
                return e
            
    if __name__ == '__main__':
        #获取参数
        mailto = [sys.argv[1]]
        title = sys.argv[2]
        content = sys.argv[3]

        status = send_mail(mailto,title,content)
        
        if status == True:
            print 1
        else:
            print status

  • 相关阅读:
    MyBatis(十)插件开发 之 插件运行原理
    通用Mapper(二)使用通用 Mapper
    通用Mapper(十四)通用Mapper接口大全
    通用Mapper(十三)通用Mapper原理
    通用Mapper(十二)通用Mapper配置项
    通用Mapper(十)二级缓存
    通用Mapper(九)通用 Mapper 接口扩展
    Linux安装与部署SonarQube
    Sonarqube分析代码并导出PDF分析报告
    SVN update失败,cleanup后再update
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429387.html
Copyright © 2020-2023  润新知