zoukankan      html  css  js  c++  java
  • telnetlib

    telnetlib是python内置模块,支持telnet协议,Telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式。它为用户提供了在本地计算机上完成远程主机工作的能力。

    内部结构:

    class telnetlib.Telnet([host[,port[,timeout]]])

    连接Telnet服务器

    生成类实例:tn=telnetlib.Telnet(Host,port=23,timeout=10)

    tn.expect(list[,timeout])

    参数是一个列表和一个超时时间

    当结果中存在一个列表中匹配的内容时返回

    (比read_until更强大)

    返回一个元祖,包含三项内容(1.list中第一个匹配的序号,2.返回匹配对象,3.读到的文本和包含的匹配)

    expect_value是一个字符串列表也可以是正则匹配列表

    timeout是超时时间,秒

    如果这个文本被查询之后没有匹配上列表中的任何内容,则raise EOFError,否则没有匹配内容时,返回(-1, None, text)text内容为目前接收到的文本(如果超时发生,可能是个空字符串),

    If a regular expression ends with a greedy match (such as .*) or if more than one expression can match the same input, the results are non-deterministic, and may depend on the I/O timing.

     
    tn.read_until(expected[,timeout])

    当结果中存在想要的信息时返回

    如果一直读取不到想要的信息就返回空字符串

    如果连接断开或没有可用的cooked data,则raise EOFError错误

       
    tn.read_all()

    读取所有数据直到EOF,或直到连接断开

       
    tn.read_some() 只要有结果就返回    
    tn.write()      
    tn.read_very_lazy() 返回缓冲区的数据    
    tn.read_lazy()      
    tn.read_very_eager()      
    tn.read_eager()       
    tn.read_sb_data()      
    tn.open(host[,port[,timeout]])      
    tn.msg(msg[,*args])      
    tn.set_debuglevel(debuglevel)      
    tn.get_socket()      
    tn.close()   关闭连接    
    tn.fileno()      
    tn.write(buffer) 写一个字符串给socket    
    tn.interact()      
    tn.mt_interact()      
    tn.set_option_negotiation_callback(callback)      

    网络连接可以用telnet传输,也可以用ssh传输,两者的区别:

       1.ssh是加密的,基于SSL,可参照paramiko类

       2.telnet是明码传输,发送的数据被监听后不需要解密就能看到内容

    ps: 远程访问可以用telnet方式,也可以用paramiko方式;连接完毕后传输网络命令,telnet/paramiko的访问方式中各自都可以用telnet命令或者ssh(封装在paramiko类中)命令

    以下为telnet访问方式中的网络传输指令

    可以用telnet.wirte('')命令获取一个socket来向网络传输命令,以下为网络命令

  • 相关阅读:
    POJ3233]Matrix Power Series && [HDU1588]Gauss Fibonacci
    [codeforces 508E]Maximum Matching
    [SDOI2011]染色
    [CSU1806]Toll
    [HDU4969]Just a Joke
    [HDU1071]The area
    [HDU1724]Ellipse
    [VIJOS1889]天真的因数分解
    [BZOJ3379] Turning in Homework
    [BZOJ1572] WorkScheduling
  • 原文地址:https://www.cnblogs.com/zz27zz/p/7904184.html
Copyright © 2011-2022 走看看