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


Python telnetlib.Telnet方法代碼示例

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


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

示例1: interactive

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def interactive(self):
        """
        Mimic an interctive session.
        """

        # Get the Telnet prompt
        prompt = self.wait_for_prompt()
        sys.stdout.write("%s" % prompt)

        while True:

            command = sys.stdin.readline().strip()

            # Fake command that ease quitting the interactive session
            if command == "exit":
                break

            self.send_command(command)
            data = self.recv_command()
            sys.stdout.write(data) 
開發者ID:guedou,項目名稱:flashre,代碼行數:22,代碼來源:telnet.py

示例2: __init__

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def __init__(self, ip, user, password, read_timeout=None):
        import telnetlib
        self.tn = telnetlib.Telnet(ip, timeout=15)
        self.read_timeout = read_timeout
        if b'Login as:' in self.tn.read_until(b'Login as:', timeout=read_timeout):
            self.tn.write(bytes(user, 'ascii') + b"\r\n")

            if b'Password:' in self.tn.read_until(b'Password:', timeout=read_timeout):
                # needed because of internal implementation details of the telnet server
                time.sleep(0.2)
                self.tn.write(bytes(password, 'ascii') + b"\r\n")

                if b'for more information.' in self.tn.read_until(b'Type "help()" for more information.', timeout=read_timeout):
                    # login succesful
                    from collections import deque
                    self.fifo = deque()
                    return

        raise PyboardError('Failed to establish a telnet connection with the board') 
開發者ID:scientifichackers,項目名稱:ampy,代碼行數:21,代碼來源:pyboard.py

示例3: portScanner

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def portScanner(url,dosyaAdi):
    raporIcerik=""
    baslangic=int(raw_input("Start port: "))
    bitis=int(raw_input("Finish port: "))
    for port in range(baslangic, bitis, 1):
        try:
            i=str(port)
            baglanti = telnetlib.Telnet(url, i)
            baglanti.write("\n")
            print "[+]", str(port), " - ", baglanti.read_all().splitlines()[0]
            raporIcerik+="[+]", str(port), " - ", baglanti.read_all().splitlines()[0]+"\n"
            baglanti.close()
        except:
            pass

    rapor = open(dosyaAdi, "a")
    rapor.write(raporIcerik)
    rapor.close() 
開發者ID:tulpar,項目名稱:tulpar,代碼行數:20,代碼來源:tulpar.py

示例4: method

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def method(url,dosyaAdi):
    try:
        telnetBaglanti = telnetlib.Telnet(url, 80)
        telnetBaglanti.write("OPTIONS / HTTP/1.1\n")
        komut = "Host: " + url + "\n\n\n\n"
        telnetBaglanti.write(komut)
        sayfa = telnetBaglanti.read_all()
        deger = str(sayfa).find("Allow")
        deger2 = str(sayfa).find("\n", deger + 1)
        Metodlar = sayfa[deger:deger2]
        print "Methods: ", Metodlar
        raporIcerik="[+]Methods: "+Metodlar+"\n"
        rapor = open(dosyaAdi, "a")
        rapor.write(raporIcerik)
        rapor.close()
    except:
        pass 
開發者ID:tulpar,項目名稱:tulpar,代碼行數:19,代碼來源:tulpar.py

示例5: _test_read_any_eager_A

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def _test_read_any_eager_A(self, func_name):
        """
        read_very_eager()
          Read all data available already queued or on the socket,
          without blocking.
        """
        want = [self.block_long, 'x' * 100, 'y' * 100, EOF_sigil]
        expects = want[1] + want[2]
        self.dataq.put(want)
        telnet = telnetlib.Telnet(HOST, self.port)
        self.dataq.join()
        func = getattr(telnet, func_name)
        data = ''
        while True:
            try:
                data += func()
                self.assertTrue(expects.startswith(data))
            except EOFError:
                break
        self.assertEqual(expects, data) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_telnetlib.py

示例6: test_read_lazy_A

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def test_read_lazy_A(self):
        want = ['x' * 100, EOF_sigil]
        self.dataq.put(want)
        telnet = telnetlib.Telnet(HOST, self.port)
        self.dataq.join()
        time.sleep(self.block_short)
        self.assertEqual('', telnet.read_lazy())
        data = ''
        while True:
            try:
                read_data = telnet.read_lazy()
                data += read_data
                if not read_data:
                    telnet.fill_rawq()
            except EOFError:
                break
            self.assertTrue(want[0].startswith(data))
        self.assertEqual(data, want[0]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_telnetlib.py

示例7: test_read_very_lazy_A

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def test_read_very_lazy_A(self):
        want = ['x' * 100, EOF_sigil]
        self.dataq.put(want)
        telnet = telnetlib.Telnet(HOST, self.port)
        self.dataq.join()
        time.sleep(self.block_short)
        self.assertEqual('', telnet.read_very_lazy())
        data = ''
        while True:
            try:
                read_data = telnet.read_very_lazy()
            except EOFError:
                break
            data += read_data
            if not read_data:
                telnet.fill_rawq()
                self.assertEqual('', telnet.cookedq)
                telnet.process_rawq()
            self.assertTrue(want[0].startswith(data))
        self.assertEqual(data, want[0]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_telnetlib.py

示例8: _test_command

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def _test_command(self, data):
        """ helper for testing IAC + cmd """
        self.setUp()
        self.dataq.put(data)
        telnet = telnetlib.Telnet(HOST, self.port)
        self.dataq.join()
        nego = nego_collector()
        telnet.set_option_negotiation_callback(nego.do_nego)
        txt = telnet.read_all()
        cmd = nego.seen
        self.assertTrue(len(cmd) > 0) # we expect at least one command
        self.assertIn(cmd[0], self.cmds)
        self.assertEqual(cmd[1], tl.NOOPT)
        self.assertEqual(len(''.join(data[:-1])), len(txt + cmd))
        nego.sb_getter = None # break the nego => telnet cycle
        self.tearDown() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_telnetlib.py

示例9: cmd

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def cmd(self, cmd_str, wait_ret=True):
        if not isinstance(cmd_str, str):
            raise TypeError("Invalid command string", cmd_str)
        if not self.is_open:
            raise attenuator.Error("Telnet connection not open for commands")

        cmd_str.strip(self.tx_cmd_separator)
        self._tn.read_until(_ascii_string(self.prompt), 2)
        self._tn.write(_ascii_string(cmd_str + self.tx_cmd_separator))
        if wait_ret is False:
            return None

        match_idx, match_val, ret_text = self._tn.expect(
            [_ascii_string("\S+" + self.rx_cmd_separator)], 1)

        if match_idx == -1:
            raise attenuator.Error(
                "Telnet command failed to return valid data")

        ret_text = ret_text.decode()
        ret_text = ret_text.strip(self.tx_cmd_separator +
                                  self.rx_cmd_separator + self.prompt)

        return ret_text 
開發者ID:google,項目名稱:mobly,代碼行數:26,代碼來源:telnet_scpi_client.py

示例10: connectraw

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def connectraw(self):
		# Try up to 10 times to connect to LMS
		connection_failed = 0
		self.rawserver = None

		logging.debug(u"Connecting to LMS raw service on {0}:{1}".format(self.server, self.port))
		while True:
			if connection_failed >= 10:
				logging.debug(u"Could not connect to raw LMS service")
				break
			try:
				# Connection to LMS
				self.rawserver = telnetlib.Telnet(self.server, self.port)

				# Subscribe to notification events that should wake up the system to collect data
				self.rawserver.write("subscribe pause,play,mixer,playlist\n".encode('ascii'))
				break
			except IOError:
				self.rawserver = None
				connection_failed += 1
				time.sleep(1)
		if self.rawserver is None:
			raise IOError(u"Could not connect raw to LMS") 
開發者ID:dhrone,項目名稱:pydPiper,代碼行數:25,代碼來源:musicdata_lms.py

示例11: test_SB_commands

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def test_SB_commands(self):
        # RFC 855, subnegotiations portion
        send = [tl.IAC + tl.SB + tl.IAC + tl.SE,
                tl.IAC + tl.SB + tl.IAC + tl.IAC + tl.IAC + tl.SE,
                tl.IAC + tl.SB + tl.IAC + tl.IAC + 'aa' + tl.IAC + tl.SE,
                tl.IAC + tl.SB + 'bb' + tl.IAC + tl.IAC + tl.IAC + tl.SE,
                tl.IAC + tl.SB + 'cc' + tl.IAC + tl.IAC + 'dd' + tl.IAC + tl.SE,
                EOF_sigil,
               ]
        self.dataq.put(send)
        telnet = telnetlib.Telnet(HOST, self.port)
        self.dataq.join()
        nego = nego_collector(telnet.read_sb_data)
        telnet.set_option_negotiation_callback(nego.do_nego)
        txt = telnet.read_all()
        self.assertEqual(txt, '')
        want_sb_data = tl.IAC + tl.IAC + 'aabb' + tl.IAC + 'cc' + tl.IAC + 'dd'
        self.assertEqual(nego.sb_seen, want_sb_data)
        self.assertEqual('', telnet.read_sb_data())
        nego.sb_getter = None # break the nego => telnet cycle 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:22,代碼來源:test_telnetlib.py

示例12: test_telnet

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def test_telnet(hostname, port):
    # This attempts to test the validity of a controller
    # It returns a tuple (probably not the best way to do this) which is in the format:
    # Initial Connection Test (bool), Version Response Test (bool), Version Response (str)
    try:
        tn = telnetlib.Telnet(host=hostname, port=port, timeout=3)
    except socket.timeout:
        return False, False, None
    except ConnectionRefusedError:
        return False, False, None

    try:
        tn.write("n\r\n")
        version_string = tn.read_until("}",3)
    except:
        return True, False, None
    return True, True, version_string


# The following was used for testing during development 
開發者ID:thorrak,項目名稱:fermentrack,代碼行數:22,代碼來源:connection_debug.py

示例13: start_bootloader

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def start_bootloader(self, bin_path):

        log.info("Starting openocd")

        proc = subprocess.Popen([
            'openocd',
                '-s', '/usr/share/openocd',
                '-f', 'assets/adapters/{}.cfg'.format(self._jtag_hardware),
                '-f', 'assets/boards/ed20.cfg'
            ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        try:
            wait = 10
            log.info("Waiting for {} seconds".format(wait))
            sleep(wait)
            client = telnetlib.Telnet('localhost', 4444)
            log.debug(client.read_until("> "))
            log.info("Halting CPU")
            client.write("soft_reset_halt\n")
            log.debug(client.read_until("> "))
            sleep(0.1)
            client.write("reset halt\n")
            log.debug(client.read_until("> "))
            sleep(0.1)
            log.info("Loading new image to RAM")
            client.write("load_image {} 0xa1f00000\n".format(bin_path))
            log.debug(client.read_until("> "))
            sleep(0.1)
            log.info("Starting up new image")
            client.write("resume 0xa1f00000\n")
        except:
            try:
                log.exception(proc.communicate()[0])
            except:
                pass
            proc.terminate()
            raise

        proc.terminate() 
開發者ID:martenjacobs,項目名稱:ToonRooter,代碼行數:41,代碼來源:rooter.py

示例14: __init__

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def __init__(self, host):
        self.tlnt = telnetlib.Telnet(host, 23)

        # Announce that we will send strings character per character
        self.write_raw(telnetlib.IAC + telnetlib.WONT + telnetlib.LINEMODE) 
開發者ID:guedou,項目名稱:flashre,代碼行數:7,代碼來源:telnet.py

示例15: close

# 需要導入模塊: import telnetlib [as 別名]
# 或者: from telnetlib import Telnet [as 別名]
def close(self):
        """
        Close the Telnet session.
        """

        return self.tlnt.close() 
開發者ID:guedou,項目名稱:flashre,代碼行數:8,代碼來源:telnet.py


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