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


Python Telnet.write方法代码示例

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


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

示例1: startBT

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
def startBT(url):
    t = Telnet(host,port)
    print t.read_until('command-line:')
    t.write('vd\r\n')
    print t.read_until('command-line:')
    t.write('startbt %s\r\n'%url)
    print t.read_until('command-line:')
开发者ID:xiaol,项目名称:ccv-impl,代码行数:9,代码来源:telnet.py

示例2: takeover_light

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
def takeover_light(ip):
    t = Telnet()
    t.open(ip, 30000)
    t.write("[Link,Touchlink]")
    output = t.read_until("[Link,Touchlink,success", 10)
    print output
    t.close()
开发者ID:sheeley,项目名称:PyHueTool,代码行数:9,代码来源:hue.py

示例3: update

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
 def update(self):
     tn = Telnet(self.host, self.port, self.timeout)
     tn.write(b'version\n')
     ret = tn.read_until(b'\r\n', self.timeout).decode('utf-8')
     logger.debug('version: %s', ret)
     version_list = ret.split(' ')
     if len(version_list) != 2 or version_list[0] != 'VERSION':
         raise ElasticacheInvalidTelentReplyError(ret)
     version = version_list[1][0:-2]
     if StrictVersion(version) >= StrictVersion('1.4.14'):
         get_cluster = b'config get cluster\n'
     else:
         get_cluster = b'get AmazonElastiCache:cluster\n'
     tn.write(get_cluster)
     ret = tn.read_until(b'END\r\n', self.timeout).decode('utf-8')
     logger.debug('config: %s', ret)
     tn.close()
     p = re.compile(r'\r?\n')
     conf = p.split(ret)
     if len(conf) != 6 or conf[4][0:3] != 'END':
         raise ElasticacheInvalidTelentReplyError(ret)
     version = int(conf[1])
     servers = []
     nodes_str = conf[2].split(' ')
     for node_str in nodes_str:
         node_list = node_str.split('|')
         if len(node_list) != 3:
             raise ElasticacheInvalidTelentReplyError(ret)
         servers.append(node_list[0] + ':' + node_list[2])
     with self.lock:
         if version > self.version:
             self.servers = servers
             self.version = version
             self.timestamp = time.time()
             logger.debug('cluster update: %s', self)
开发者ID:yupeng820921,项目名称:elasticache_pyclient,代码行数:37,代码来源:memcache_client.py

示例4: set_state

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
    def set_state(self, state):
        s = 'On' if state else 'Off'

        tel = Telnet(self.bar.host)

        try:
            time.sleep(2.)

            garbage = tel.read_very_eager()
            print('GarbageRead:', garbage)

            w = "/%s %d" % (s, self.ident)
            msg = w.encode('ascii') + b"\r\n"
            print("Writing:", repr(msg))
            tel.write(msg)

            print("Reading:", repr(tel.read_until("NPS>", timeout=5)))

            time.sleep(1.)
            garbage = tel.read_very_eager()
            print('GarbageRead2:', garbage)

            self.state = state
        finally:
            tel.close()

        del tel

        time.sleep(0.5)
开发者ID:MerlijnWajer,项目名称:powerbars,代码行数:31,代码来源:wtibar.py

示例5: connectToServer

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
def connectToServer(hostIP = "10.10.100.254", port = 8899):
    HOST = hostIP #Host IP Address
    PORT = port   #Host port number

    pingStr = "ping "+HOST #Attempt to ping host
    if (os.system(pingStr)==0): #Host able to be pinged
        print "Robot found...", #Comma prevents printed line from wrapping
        try: #Attempt to connect to remote host
            tn = Telnet(host = HOST, port = PORT)
            print "Connected!"
        except Exception as E: #Failed connection
            print "Connection failed!"
            raise E
    else:                       #Host not found
        print "Host not found"
        raise ValueError('Could not connect to a host')

    print "Transmitting..."
    cmdSet = [['SPL','!C'], #Clear buffer
              ['SPL','!?'], #Request command buffer
              ['SPL','!N'], #Request ID
              ['CMD','1',50,51,52], #Transmit commands
              ['CMD','A',98,99,100],
              ['SPL','!?'], #Request command buffer
              ['SPL','!N']] #Request ID
    cmdSetStr = cmdSet2Str(cmdSet)
    tn.write(cmdSetStr)

    sleep(0.5) #Wait after transmitting
    return tn
开发者ID:jttaufa,项目名称:Rattus2,代码行数:32,代码来源:Telnet_RXTX.py

示例6: _connect

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
def _connect(config):
    """Boilerplate to connect to a conviron."""
    # Establish connection
    telnet = Telnet(config.get("Conviron", "Host"))
    response = telnet.expect([re.compile(b"login:")], timeout=TIMEOUT)
    LOG.debug("Initial response is: {0!s}".format(response[2].decode()))
    if response[0] < 0:  # No match found
        raise RuntimeError("Login prompt was not received")
    # Username
    payload = bytes(config.get("Conviron", "User") + "\n", encoding="UTF8")
    telnet.write(payload)
    response = telnet.expect([re.compile(b"Password:")], timeout=TIMEOUT)
    LOG.debug("Sent username: {0!s}".format(payload.decode()))
    LOG.debug("Received: {0!s}".format(response[2].decode()))
    if response[0] < 0:  # No match found
        raise RuntimeError("Password prompt was not received")
    # Password
    payload = bytes(config.get("Conviron", "Password") + "\n", encoding="UTF8")
    telnet.write(payload)
    response = telnet.expect([re.compile(b"#")], timeout=TIMEOUT)
    LOG.debug("Send password: {0!s}".format(payload.decode()))
    LOG.debug("Received: {}".format(response[2].decode()))
    if response[0] < 0:  # No match found
        raise RuntimeError("Shell prompt was not received")
    return telnet
开发者ID:borevitzlab,项目名称:SpectralPhenoClimatron-control,代码行数:27,代码来源:chamber.py

示例7: cmd

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [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

示例8: initConnection

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
def initConnection(host, port, timeout):
    """initiate connection to PNA and returns Telnet object tn
    
    if connection is succesfull returns object tn
    """
    try:
        tn = Telnet(host, port, timeout)
        ans = tn.read_until("SCPI> ".encode(encoding='ascii', errors='strict'), timeout = 10).decode('ascii').strip()
        
        if debugCommunication:
            print(ans)
        else:
            pass
        
        tn.write("*IDN?".encode(encoding='ascii', errors='strict'))
        tn.write(termChar.encode(encoding='ascii', errors='strict'))   # just send ENTER to execute the command
        
        ans = tn.read_until("SCPI> ".encode(encoding='ascii', errors='strict'), timeout = 5).decode('ascii').strip()
        
        if debugCommunication:
            print(ans)
        else:
            pass   
        
        return tn
    
    except:
        print("Error while connecting.")
开发者ID:borisov-r,项目名称:EM3Dscanner,代码行数:30,代码来源:communication_PNA.py

示例9: __init__

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
 def __init__(self, endpoint, timeout):
     host, port = endpoint.split(':')
     elasticache_logger.debug('cluster: %s %s %s %s %s %s',
                              str(host), str(type(host)),
                              str(port), str(type(port)),
                              str(timeout), str(type(timeout)))
     tn = Telnet(host, port)
     tn.write('version\n')
     ret = tn.read_until('\r\n', timeout)
     elasticache_logger.debug('version: %s', ret)
     version_list = ret.split(' ')
     if len(version_list) != 2 or version_list[0] != 'VERSION':
         raise ElasticacheInvalidTelentReplyError(ret)
     version = version_list[1][0:-2]
     if StrictVersion(version) >= StrictVersion('1.4.14'):
         get_cluster = 'config get cluster\n'
     else:
         get_cluster = 'get AmazonElastiCache:cluster\n'
     tn.write(get_cluster)
     ret = tn.read_until('END\r\n',  timeout)
     elasticache_logger.debug('config: %s', ret)
     tn.close()
     p = re.compile(r'\r?\n')
     conf = p.split(ret)
     if len(conf) != 6 or conf[4][0:3] != 'END':
         raise ElasticacheInvalidTelentReplyError(ret)
     self.version = conf[1]
     self.servers = []
     nodes_str = conf[2].split(' ')
     for node_str in nodes_str:
         node_list = node_str.split('|')
         if len(node_list) != 3:
             raise ElasticacheInvalidTelentReplyError(ret)
         self.servers.append(node_list[1] + ':' + node_list[2])
开发者ID:root360,项目名称:elasticache_pyclient,代码行数:36,代码来源:memcache_client.py

示例10: lineprofile

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
 def lineprofile(self, params):
     try:
         echo = params[18].split("_")
         print("Telnet " + params[6])
         tn = Telnet()
         tn.open(params[6], 23, self.telnetTimeout)
         
         if "9800" in params[1]: tn.write("\n")
         print(tn.read_until(echo[0], self.cmdTimeout))
         tn.read_until("\xff\xfc\x03", 1)
         
         for i in [1,2,3,4,5,7,9,10,8]:
             if params[i+7] <> "":
                 tn.write(params[i+7] + "\n")
                 if i == 9 and "HW" in params[1]: print(tn.read_until(": ", self.cmdTimeout)),
                 print(tn.read_until(echo[i], self.cmdTimeout)),
                 
         print("\n\nBDID: %s" % params[0])
         print("Equipment Type: %s (%s)" % (params[1], params[6]))
         print("L112 Port: %s" % params[5])
         print("Equipment Port: %s/%s/%s" % (params[2], params[3], params[4]))
     except:
         print("Execute command fail.")
     finally:
         tn.close()
开发者ID:flowsha,项目名称:zhwh,代码行数:27,代码来源:Port.py

示例11: getchannellist

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [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

示例12: MitutoyoConnection

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
class MitutoyoConnection(object):
    # telnet connection to terminal server
    host = "10.1.1.35"
    port = 10001
    def __init__(self):
        try:
            self.telnet = Telnet(self.host, self.port)
        except:
            print("Cannot connect to mitutoyo host!! Check connections and try again or use manual entry")
            self.telnet = None

    def queryGauges(self):
        radialFloats = []
        for gaugeNum in range(1,6):
            self.telnet.write("D0%i\r\n"%gaugeNum)
            gaugeOutput = self.telnet.read_until("\r", 1)
            try:
                gauge, val = gaugeOutput.strip().split(":")
                gauge = int(gauge)
                val = float(val)
                assert gauge == gaugeNum
                print("gauge %i: %.4f"%(gauge, val))
            except:
                raise RuntimeError("Failed to parse gauge %i output: %s"%(gaugeNum, gaugeOutput))
            radialFloats.append(val)
        return radialFloats
开发者ID:csayres,项目名称:fitPlateProfile,代码行数:28,代码来源:mitutoyo.py

示例13: tlnt_connect

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
def tlnt_connect(doc, timeout):
    print2('connecting')
    tn = Telnet(doc['server'])
    print2('sending username')
    s = tn.read_until(b'Username: ', timeout)
    cmd = doc['login'] + '\n\r'
    tn.write(cmd.encode('ascii'))
    print2('sending password')
    s = tn.read_until(b'Password: ', timeout)
    cmd = doc['password'] + '\n\r'
    tn.write(cmd.encode('ascii'))
    t = tn.expect([b'\r\n/', b'\r\nUser authorization failure\r\n'])
    if t[0] in [1, -1]:
        tn.close()
        return
    s = t[2]
    s = s.decode('ascii')
    i1 = s.find('AT')
    i2 = s.find('/')
    dd = s[i1+3:i2]
    hh = s[i2+1:i2+3]
    doc['dd2'] = dd
    doc['hh2'] = hh
    hhh = 24*int(dd) + int(hh)
    hhh -= int(doc['hh'])
    if hhh < 0:
        hhh = 0
    doc['dd1'] = '%d' % (hhh/24)
    doc['hh1'] = '%d' % (hhh%24)
    return tn
开发者ID:ivanovev,项目名称:ascft,代码行数:32,代码来源:ascft.py

示例14: __init__

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
    class Session:
        def __init__(self, host, port, username, password):
            self.telnet = Telnet(host, port, 5)
            self.read_until("Login id:")
            self.write(username +"\n")
            self.read_until("Password:")
            self.write(password +"\n")
            self.read_until("Welcome root.HELP for a list of commands")

        def read_until(self, text):
            self.telnet.read_until(text.encode('ascii'), 5)

        def write(self, text):
            self.telnet.write(text.encode('ascii'))

        def is_user_registered(self, username):
            self.write("verify %s\n" % username)
            res = self.telnet.expect([b"exists", b"does not exist"])
            return res[0] == 0

        def create_user(self, username, password):
            self.write("adduser %s %s\n" % (username, password))
            self.read_until("User %s added" % username)

        def reset_password(self, username, password):
            self.write("setpassword %s %s\n" % (username, password))
            self.read_until("Password for %s reset" % username)

        def quit(self):
            self.write("quit\n")
开发者ID:galaktika81,项目名称:python_training_mantis,代码行数:32,代码来源:james.py

示例15: get

# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import write [as 别名]
def get(host="localhost", port=4242):
    tel = Telnet(host, port)
    _get(tel)
    tel.write("content.location.href")
    result = _get(tel)
    tel.close()
    return result[0].strip('"')
开发者ID:brejoc,项目名称:supergenpass,代码行数:9,代码来源:firefox_url.py


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