나는 pxssh를 사용하여 간단한 ssh 로그인 작업을하고 있습니다. T.J. 요리 책의 코너 스크립트.pxssh로 고정되었습니다. 첫 번째 로그인에 성공하면 다시 로그인하지 않습니까?
파이썬 인터프리터에서 시도 할 때 pxssh를 사용하여 원격 컴퓨터에 성공적으로 액세스하고 명령을 전달할 수있었습니다. 다음은보기입니다. 내가 다시 같은 일을하려고 할 때 또한 EOF의 예외에
#! /usr/bin/python -tt
from pexpect import pxssh
import pexpect
def send_commands(s, command):
s.sendline(command)
s.prompt(pexpect.EOF)
print s.before
def connect(host, username, password):
try:
child = pxssh.pxssh()
child.login(host, username, password)
return child
except Exception, e:
print "[-] Error Connecting\n" + str(e)
exit(0)
def main():
s = connect('192.168.1.107', 'shineesh', 'password123')
send_commands(s, 'ifconfig')
if __name__ == '__main__':
main()
----- 출력을 발생 아래
>>> from pexpect import pxssh
>>> s = pxssh.pxssh()
>>> s.login("192.168.1.107", "shineesh", "password123")
True
>>> s
<pexpect.pxssh.pxssh object at 0xb72d772c>
>>> s.sendline("ifconfig")
9
>>> s.prompt()
True
>>> print s.before
ifconfig
eth0 Link encap:Ethernet HWaddr 3X:XX:XX:XX:XX:X4
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
지금,이
>>> s = pxssh.pxssh()
>>> s.login("192.168.1.107", "shineesh", "password123")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 331, in login
if not self.sync_original_prompt(sync_multiplier):
File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 218, in sync_original_prompt
b = self.try_read_prompt(sync_multiplier)
File "/usr/lib/python2.7/dist-packages/pexpect/pxssh.py", line 182, in try_read_prompt
prompt += self.read_nonblocking(size=1, timeout=timeout)
File "/usr/lib/python2.7/dist-packages/pexpect/pty_spawn.py", line 455, in read_nonblocking
return super(spawn, self).read_nonblocking(size)
File "/usr/lib/python2.7/dist-packages/pexpect/spawnbase.py", line 149, in read_nonblocking
raise EOF('End Of File (EOF). Exception style platform.')
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
>>>
스크립트를 얻을 Below-- ------------
[-] Error Connecting
End Of File (EOF). Exception style platform.
는 다시
http://stackoverflow.com/questions/24919980/pxssh-throwing-end-of-file-eof-exception-style-platform-exception
http://pexpect.sourceforge.net/doc/
---------- 새로운 스크립트에서 몇 스레드/참조 --------------
#! /usr/bin/python -tt
from pexpect import pxssh
import pexpect
def send_commands(s, command):
s.sendline(command)
s.prompt(pexpect.EOF)
print s.before
def connect(host, username, password):
try:
child = pxssh.pxssh()
child.login(host, username, password)
child.expect(pexpect.EOF, timeout=None)
return child
except Exception, e:
print "[-] Error Connecting\n" + str(e)
exit(0)
def main():
s = connect('192.168.1.107', 'shineesh', 'password123')
send_commands(s, 'ls -all')
if __name__ == '__main__':
main()
을 따라
------- 출력 -------------은
[-] Error Connecting
End Of File (EOF). Exception style platform.
는 어디에서 잘못 여기에 갈거야?