本文整理汇总了Python中telnetlib.Telnet.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Telnet.__init__方法的具体用法?Python Telnet.__init__怎么用?Python Telnet.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telnetlib.Telnet
的用法示例。
在下文中一共展示了Telnet.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, force_ssl=True, telnet_tls=True, **kwargs):
"""
Called just like telnetlib.Telnet(), with these extra options:
force_ssl - If True, force SSL negotiation as soon as connected.
Defaults to True.
telnet_tls - If true, allow TELNET TLS negotiation after non-ssl
connection. Defaults to True.
Also accepts args to ssl.wrap_socket()
If force_ssl is True, plaintext connections aren't allowed.
If force_ssl is False, and telnet_tls is True, the connection
will be plaintext until the server negotiates TLS, at which
time the connection will be secured.
If both are False, the connection will be plaintext.
"""
self.in_tls_wait = False
self.tls_write_buffer = b''
self.secure = False
self.force_ssl = force_ssl
self.allow_telnet_tls = telnet_tls
self.ssltelnet_callback = None
ssl_argnames = {
'keyfile', 'certfile', 'cert_reqs', 'ssl_version',
'ca_certs', 'suppress_ragged_eofs', 'ciphers',
}
self.ssl_args = {k: v for k, v in kwargs.items() if k in ssl_argnames}
telnet_args = {k: v for k, v in kwargs.items() if k not in ssl_argnames}
Telnet.__init__(self, **telnet_args)
Telnet.set_option_negotiation_callback(self,
self._ssltelnet_opt_cb)
示例2: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__ (self, port=monBase): # 1st usable IP = monBase +2 # host='localhost',
Telnet.__init__(self)
self.host = 'localhost'
self.port = port
self.history = History()
#self.rlock = RLock() # from man kvm: "Only one TCP connection at a time is accepted"
if self.trace: self.set_debuglevel(1)
示例3: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self,host,port):
try:
Telnet.__init__(self,host,port)
except:
print "Cannot connect to:", host, port
self.prompt = []
self.prompt.append( re.compile('/[^>]*> ') )
self.timeout = 2
示例4: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, stream, logfile):
Telnet.__init__(self, host=None)
self.stream = stream
self.logfile = logfile
self.eof = 0
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.connect(stream)
示例5: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, host_port_timeout, secret=None, **kwargs):
if isinstance(host_port_timeout, basestring):
host_port_timeout = host_port_timeout.split(':')
Telnet.__init__(self, *host_port_timeout)
(status, length), content = self._read()
if status == 107 and secret is not None:
self.auth(secret, content)
elif status != 200:
logging.error('Connecting failed with status: %i' % status)
示例6: Expect
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def Expect(self,pat , wait=2, nowait=False):
self.fExpecting=True
if wait==None:
wait=0.5
else:
wait = float(wait)
found =None
m =None
if not nowait:
if not self.fInteractionMode:
output =self.expect(["%s"%(pat)],float(wait))
self.output=output[2]
m =sre.search('%s'%(pat), self.output, sre.M|sre.DOTALL)
else:
interval=0.1
counter =0
max_counter=round(float(wait)/interval)+1
interactionpat = '(%s)(.*)'%pat
while counter<max_counter:
counter+=1
m =sre.search(interactionpat,self.InteractionBuffer,sre.M|sre.DOTALL)
if m:
self.InteractionMatch=m.group(0)
self.InteractionBuffer=m.group(1)#.decode("utf-8")
break
time.sleep(interval)
else:
m = sre.search(pat,self.output, sre.M|sre.DOTALL)
self.seslog.flush()
self.fExpecting=False
if not m:
raise Exception('Expect("%s", %f) Failed'%(pat,float(wait)))
self.match = m.group()
global reSessionClosed
mSesClosed= sre.search(reSessionClosed,self.output)
isalive = self.isalive()
if (self.Connect2SUTDone):
if (mSesClosed):
command = self.attrs['CMD']
self.error("Session(%s) has been closed by remote host!"%(self.sutname))
if command.find('telnet')!=-1:
host=""
port=23
args = command.split(' ')
if len(args)==2:
host = args[1]
elif len(args)==3:
host= args [1]
port = args[2]
spawn.__init__(self, host, port)
self.set_debuglevel(1)
self.Login2SUT()
return self.output
示例7: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, host=None, port=Defaults.port, keyfile=Defaults.keyfile, certfile=Defaults.certfile, verifyfile=Defaults.verifyfile):
## Same as normal, but make it secure:
self.ctx = SSL.Context(SSL.SSLv23_METHOD)
self.ctx.set_options(SSL.OP_NO_SSLv2)
if verifyfile:
self.ctx.set_verify(SSL.VERIFY_PEER, self.verify_cb) # Demand a certificate
self.ctx.load_verify_locations(os.path.join(dir, verifyfile))
self.ctx.use_privatekey_file (keyfile)
self.ctx.use_certificate_file(certfile)
Telnet.__init__(self, host, port)
示例8: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, hostname, port, timeout, pipe_in, pipe_out, keep_alive=30, poll_interval=0.125):
self.pipe_in = pipe_in
self.pipe_out = pipe_out
self.logger = logging.getLogger('teamspeak3.TeamspeakConnection')
self.commands_unresponded = deque()
self.keep_alive = keep_alive
self.poll_interval = poll_interval
Telnet.__init__(self, hostname, port, timeout)
示例9: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, host_port_timeout, **opts):
if isinstance(host_port_timeout, basestring):
host_port_timeout = host_port_timeout.split(':')
self.secret = opts.get('secret', None)
Telnet.__init__(self, *host_port_timeout)
# Read first response from Varnish
(status, length), content = self._read()
if status == 107 and self.secret:
# Authenticate before continuing.
m = hashlib.sha256()
challenge = content[:32]
m.update(challenge + '\n' + self.secret + '\n' + challenge + '\n')
self.fetch('auth ' + m.hexdigest())
示例10: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, server):
host_port_timeout = server.addr
secret = server.secret
if isinstance(host_port_timeout, basestring):
host_port_timeout = host_port_timeout.split(':')
Telnet.__init__(self, *host_port_timeout)
# Eat the preamble ...
#self.read_until("Type 'quit' to close CLI session.\n\n")
if secret:
self.auth_token = self.read_until("Authentication required.\n\n").split('\n')[1]
resp = self.auth(VarnishAuth(secret).auth_hash(self.auth_token))
self.read_until("\n")
else:
self.read_until("Type 'quit' to close CLI session.\n\n")
示例11: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, host, port, name, secret=None, version=30, timeout=5):
# Try to establish connection.
Telnet.__init__(self, host, port, timeout)
self.name = name
self.version = version
(status, length), content = self._read()
# Authentication requested?
if status == 107:
if secret:
self._auth(secret, content)
else:
raise Varnish.Exception(self.error_messages['missing_secret'])
# Failed connection?
elif status != 200:
raise Varnish.Exception(self.error_messages['failed_connection'] % {
'status': status,
})
示例12: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self,name,attrs={},logger=None, logpath=None):
baseSession.__init__(self, name,attrs,logger,logpath)
host=""
port=23
reHostOnly= sre.compile('\s*telnet\s+([\d.\w\-_]+)\s*',sre.I)
reHostPort = sre.compile('\s*telnet\s+([\d.\w]+)\s+(\d+)', sre.I )
command = attrs.get('CMD')
m1=sre.match(reHostOnly, command)
m2=sre.match(reHostPort, command)
if m1:
host= m1.groups(1)[0]
elif m2:
host= m2.groups(1)[0]
port= m2.groups(2)[0]
spawn.__init__(self, str(host), port)
self.set_debuglevel(0)
self.Login2SUT()
self.Connect2SUTDone=True
示例13: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, host_port_timeout):
if isinstance(host_port_timeout, basestring):
host_port_timeout = host_port_timeout.split(':')
Telnet.__init__(self, *host_port_timeout)
示例14: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, host_port_timeout):
if isinstance(host_port_timeout, basestring):
host_port_timeout = host_port_timeout.split(':')
Telnet.__init__(self, *host_port_timeout)
# Eat the preamble ...
self.read_until("Type 'quit' to close CLI session.\n\n")
示例15: __init__
# 需要导入模块: from telnetlib import Telnet [as 别名]
# 或者: from telnetlib.Telnet import __init__ [as 别名]
def __init__(self, *args):
Telnet.__init__(self, *args)
self.read_until("Type 'quit' to close CLI session.\n\n")