当前位置: 首页>>代码示例>>Python>>正文


Python Telnet.read_all方法代码示例

本文整理汇总了Python中telnetlib.Telnet.read_all方法的典型用法代码示例。如果您正苦于以下问题:Python Telnet.read_all方法的具体用法?Python Telnet.read_all怎么用?Python Telnet.read_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telnetlib.Telnet的用法示例。


在下文中一共展示了Telnet.read_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: telnet_handler

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
def telnet_handler(host, dump, passw, set_name):
    if not host:
        host = '127.0.0.1'
    port = 23
    tftphost = '200.2.127.150'
    tftppath = ''  # e.g: tftppath = 'mdump/'

    # connect
    print "Connecting to %s..." % host
    tn = Telnet(host, port)
    #tn.set_debuglevel(5)

    #print "waiting for login string..."
    tn.read_until("login: ")
    tn.write('admin' + "\n")
    #print "waiting for password string..."
    tn.read_until("password: ")
    tn.write(passw + "\n")

    tn.read_until(set_name + "> ")
    cmd = "dump network %s %s" % (tftphost, tftppath + dump)
    print "running \"%s\" on host %s" % (cmd, host)
    tn.write(cmd + '\n')

    tn.read_until(set_name + "> ")
    tn.write('logout\n')
    print "Logging out from %s..." % host

    print tn.read_all()

    print "Bye."
开发者ID:cgfuh,项目名称:try_git,代码行数:33,代码来源:download_new_dump.py

示例2: _show_run

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
 def _show_run(self,get_switch,get_switch_property,get_switch_access):
  ### variable arrange
  switch_name = get_switch['name']
  network_inform = get_switch['ip']
  telnet_port = network_inform.split(':')[1]
  telnet_ip = network_inform.split(':')[0].split('/')[0]
  telnet_user = get_switch_access['account']
  telnet_pass = get_switch_access['password']
  telnet_enable = get_switch_access['enable']
  ### telnet open time out in second
  self.telnet_open_timeout = float(10)

  ### telnet open processing
  try:
   telnet_pointer =  Telnet(telnet_ip,telnet_port,self.telnet_open_timeout)
  except:
   msg="[ error : "+time.asctime()+" ] can't open the telnet, ip : "+telnet_ip+", port :"+telnet_port
   self.logging_msg(self.run_syslog,msg)
   sys.exit()


  ### telnet login processing
  try:
   line_result = telnet_pointer.expect(Arista_manage._login_pattern,self.telnet_open_timeout)[1]
  except:
   msg="[ error : "+time.asctime()+" ] can't 2read login pattern : "+str(Arista_manage._login_pattern)
   self.logging_msg(self.run_syslog,msg)
   sys.exit()

  if not line_result:
   sys.exit()


  ### insert account for login
  telnet_pointer.write(telnet_user+"\n")

  ### wait the password pattern
  try:
   telnet_pointer.expect(Arista_manage._passwd_pattern,self.telnet_open_timeout)
  except:
   msg="[ error : "+time.asctime()+" ] can't read login pattern : "+str(Arista_manage._passwd_pattern)
   self.logging_msg(self.run_syslog,msg)
   sys.exit()

  telnet_pointer.write(telnet_pass+"\n")
  print telnet_pointer.expect([switch_name+"\w*>"],self.telnet_open_timeout)
  telnet_pointer.write("enable1234\n")
  print telnet_pointer.expect(Arista_manage._passwd_pattern,self.telnet_open_timeout)
  telnet_pointer.write(telnet_enable+"\n")
  print telnet_pointer.expect([switch_name+"\w*#"],self.telnet_open_timeout)


  telnet_pointer.write("exit\n")
  telnet_pointer.read_all()

  telnet_pointer.close()
开发者ID:parkjunhyo,项目名称:Telnet_ejun,代码行数:58,代码来源:arista_arista_switch.py

示例3: cmd_wan_reconnect

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
def cmd_wan_reconnect(ensoapi):
    """Reconnect WAN"""
    tn = Telnet(HOST)
    tn.read_until("login: ")
    tn.write(USER + "\n")
    tn.read_until("Password: ")
    tn.write(PASSWORD + "\n")

    tn.write("killall -HUP pppd\n")
    tn.write("exit\n")
    tn.read_all()
开发者ID:BhaaLseN,项目名称:enso-portable,代码行数:13,代码来源:dd_wrt.py

示例4: cmd_wake_slave

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
def cmd_wake_slave(ensoapi):
    """Wake a slave server with a magic packet"""
    tn = Telnet(HOST)
    tn.read_until("login: ")
    tn.write(USER + "\n")
    tn.read_until("Password: ")
    tn.write(PASSWORD + "\n")

    tn.write("/usr/sbin/wol -i 192.168.1.255 -p 9 00:00:00:00:00:00\n") # provide a MAC address
    tn.write("exit\n")
    tn.read_all()
开发者ID:BhaaLseN,项目名称:enso-portable,代码行数:13,代码来源:dd_wrt.py

示例5: __init__

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
class TelnetPhapiServer:

    from telnetlib import Telnet

    def __init__(self, target, cmd="phapiserver", killold=True):
        self.tn = Telnet(target);
        if killoold:
            self.tn.write("killall phapiserver\r\nexit\r\n")

    def terminate(self):
        self.tn.read_all()
开发者ID:gabrieldelsaint,项目名称:UIM,代码行数:13,代码来源:miniuadrvr.py

示例6: connect

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
	def connect(self):
		tn = Telnet("localhost")
		out = tn.read_until("login:", 3)
		tn.write("root\n")
		check = tn.read_until("Password:", 2)
		out += check
		if check.__contains__("Password:"):
			tn.write(self.oldp + "\n")
			check = tn.read_until("~#", 2)
			out += check
		if check.__contains__("~#"):
			tn.write("passwd\n")
			out += tn.read_until("password", 2)
			tn.write(self.newp + "\n")
			out += tn.read_until("password", 2)
			tn.write(self.newp + "\n")
			out += tn.read_until("xxx", 1)
			tn.write("exit\n")
			out += tn.read_all()
		else:
			out += "\nLogin incorrect, wrong password."
			tn.close()
		
		self.connected = False
		self["lab"].setText(out)
开发者ID:E2OpenPlugins,项目名称:e2openplugin-ChangeRootPassword,代码行数:27,代码来源:plugin.py

示例7: getchannellist

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
def getchannellist(host="192.168.1.23", port=6419):
	t = Telnet(host, port)
	t.write("LSTE\nQUIT\n")
	items = t.read_all().split("\r\n")
	#lines = filter(lambda s: s.startswith("250"), lines)
#	items = map(lambda s: s[4:].split(":"), lines)
	return items
开发者ID:VollMich,项目名称:vdrcontrol,代码行数:9,代码来源:test.py

示例8: cmd

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
 def cmd(self, word):
     """Connect and send a 4letter command to Zookeeper.
     """
     # Zookeeper closes the socket after every command, so we must reconnect every time.
     tn = Telnet(self.host, self.port, self.timeout)
     tn.write('{}\n'.format(word))
     return tn.read_all()
开发者ID:funollet,项目名称:nagios-plugins,代码行数:9,代码来源:check_zookeeper.py

示例9: update

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
 def update(self):
     """Get the latest data from hhtemp running as daemon."""
     try:
         connection = Telnet(host=self.host, port=self.port, timeout=DEFAULT_TIMEOUT)
         self.data = connection.read_all().decode("ascii")
     except ConnectionRefusedError:
         _LOGGER.error("HDDTemp is not available at %s:%s", self.host, self.port)
         self.data = None
开发者ID:dmeulen,项目名称:home-assistant,代码行数:10,代码来源:hddtemp.py

示例10: cmd_wake

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
def cmd_wake(ensoapi, machine):
    """Wake a workstation with a magic packet sent to a given MAC-address
Requires the following variables at the custom initialization block:<br>
DD_WRT_HOST = "dd-wrt router ip" #default: "192.168.1.1"<br>
DD_WRT_USER = "dd-wrt user" #default: "root"<br>
DD_WRT_PASSWORD = "my_dd_wrt_password"<br>
DD_WRT_MACHINES = {'server': "AA:BB:CC:DD:EE:FF", 'gateway': "AA:BB:CC:DD:EE:FE"}
"""
    tn = Telnet(HOST, 23)
    tn.read_until(b"login: ")
    tn.write(USER + b"\n")
    tn.read_until(b"Password: ")
    tn.write(PASSWORD + b"\n")

    tn.write(b"/usr/sbin/wol -i 192.168.1.255 -p 9 "
             + MACHINES[machine].encode('ascii', 'ignore') + b"\n")
    tn.write(b"exit\n")
    tn.read_all()
开发者ID:GChristensen,项目名称:enso-portable,代码行数:20,代码来源:dd_wrt.py

示例11: status

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
 def status(self):
     status = initdv2.ParametrizedInitScript.status(self)
     if not status and self.socks:
         ip, port = self.socks[0].conn_address
         telnet = Telnet(ip, port)
         telnet.write('HEAD / HTTP/1.0\n\n')
         if 'server: nginx' in telnet.read_all().lower():
             return initdv2.Status.RUNNING
         return initdv2.Status.UNKNOWN
     return status
开发者ID:yoyama,项目名称:scalarizr,代码行数:12,代码来源:nginx.py

示例12: _exec_command

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
    def _exec_command(self):
        tn = Telnet(self._server, self._port, timeout=30)
        # tn.read_until('login: ')
        # tn.write(username + '\n')
        # tn.read_until('password: ')
        # tn.write(password + '\n')
        # tn.read_until(finish)
        tn.write('%s\n' % self._zkCommand)
#        tn.write('conf\n')
        tn.write('quit\n')
        self._value_raw = tn.read_all()
开发者ID:20988902,项目名称:collection-of-zabbix-templates,代码行数:13,代码来源:getZookeeperInfo.py

示例13: _telnet

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
def _telnet(ip, port, input):
    tn = Telnet(ip, port)
    tn.write(input + '\n')
    output = ''
    try:
        output = tn.read_all()
    except:
        print 'error in reading telnet response...'
        tn.close()
        raise
    tn.close()
    return output
开发者ID:linas,项目名称:linkgrammar-relex-web,代码行数:14,代码来源:views.py

示例14: get_data

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
	def get_data(self):
		self.hds = []
		try:
			tn = Telnet(self.host, self.port)
			data = tn.read_all()
			data = unicode(data, errors='ignore')
			data = data.replace('\x10', '')
			tn.close()
			data = data.split('||')
			for i in data: self.hds.append(i.lstrip('|').rstrip('|').split('|'))
		except:
			self.hds = None
开发者ID:infinicode,项目名称:computertemp,代码行数:14,代码来源:temp_hddtemp.py

示例15: main

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import read_all [as 别名]
def main(hostname, username, password):
    t = Telnet(hostname)
    # t.set_debuglevel(1)        # uncomment to get debug messages
    t.set_option_negotiation_callback(process_option)
    t.read_until(b'login:', 10)
    t.write(username.encode('utf-8') + b'\r')
    t.read_until(b'assword:', 10)    # first letter might be 'p' or 'P'
    t.write(password.encode('utf-8') + b'\r')
    n, match, previous_text = t.expect([br'Login incorrect', br'\$'], 10)
    if n == 0:
        print("Username and password failed - giving up")
    else:
        t.write(b'exec echo My terminal type is $TERM\n')
        print(t.read_all().decode('ascii'))
开发者ID:xenron,项目名称:sandbox-dev-python,代码行数:16,代码来源:telnet_codes.py


注:本文中的telnetlib.Telnet.read_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。