[英]telnet connection to apc with python script
I am trying to telnet to apc machine, but seeing issue with pexpect. 我正在尝试通过telnet到apc机,但是看到pexpect的问题。 I do not have ssh on the machine, so need to use telnet only. 我的机器上没有ssh,因此只需要使用telnet。
#!/usr/local/bin/python
import pexpect
import sys
import time
apc_ip = "x.x.x.x"
user = "x"
passwd = "y"
outlet = "z"
switch = pexpect.spawn('telnet x.x.x.x')
switch.logfile = sys.stdout
switch.timeout = 10
switch.expect('User Name : ')
switch.send('x' + '\r\n')
switch.expect('Password : ')
switch.sendline('y' + '\r\n')
switch.expect('apc>')
Here is what I see when I run it: 这是我运行它时看到的内容:
[~]$ python 1.py
Trying x.x.x.x...
Connected to x.x.x.x.
Escape character is '^]'.
User Name : x
apc
Password : x
****
User Name :
Do I need to flush the output somewhere? 我需要在某处刷新输出吗? Each time I run, I hit different issues, tried '\\r', '\\n' everything. 每次运行时,我都会遇到不同的问题,并尝试一切'\\ r','\\ n'。
Here is the manual output: 这是手动输出:
[ops@cn68xx ~]$ telnet x.x.x.x
Trying x.x.x.x...
Connected to x.x.x.x.
Escape character is '^]'.
User Name : x
Password : ***
Schneider Electric Network Management Card AOS v6.4.4
(c) Copyright 2016 All Rights Reserved RPDU 2g APP v6.4.4
-------------------------------------------------------------------------------
Name : apcFABE5B Date : 08/03/2017
Contact : Unknown Time : 12:05:27
Location : Unknown User : Super User
Up Time : 1 Day 1 Hour 19 Minutes Stat : P+ N4+ N6+ A+
Type ? for command listing
Use tcpip command for IP address(-i), subnet(-s), and gateway(-g)
apc>
Can someone please help me resolving this issue? 有人可以帮我解决这个问题吗?
I founded this problem of APC interpreter too. 我也提出了APC解释器的这个问题。 Problem is in /r symbol. 问题在/ r符号中。 Use something like this (it works): 使用类似这样的东西(有效):
t = pexpect.spawn('telnet 10.0.0.2')
t.expect('User Name : ')
t.send('apc\r')
t.expect('Password : ')
t.send('apc\r')
time.sleep(1)
t.expect('apc>')
t.send('uio -st 1\r')
t.expect('apc>')
t.sendline('exit')
time.sleep(2)
print t.before
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.