2017-08-04 1 views
0

私はapcマシンにtelnetしようとしていますが、pexpectの問題があります。 私はマシンにsshを持っていないので、telnetだけを使う必要があります。ここでpythonスクリプトによるapcへの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>') 

は、私はそれを実行したときに、私が見たものである。

[~]$ 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 : 

は、私がどこかに出力をフラッシュする必要がありますか?私が走るたびに、私はさまざまな問題にぶつかり、 '\ r'、 '\ n'のすべてを試しました。ここで

は手動出力されます。

[[email protected] ~]$ 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> 

誰かがこの問題を解決する私を助けてくださいことはできますか?

+0

組み込み['telnet'ライブラリ](https://docs.python.org/2/library/telnetlib.html)を試しましたか? –

+0

はい、私は試しました。しかしdint仕事。 –

答えて

0

私はAPCインタープリタのこの問題も発見しました。問題は/ rシンボルにあります。このようなものを使用してください(それは動作します):

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 
関連する問題