Send Commands To A Remote Machine Application With Python
I want to do the following in Python. Connect to a remote machine open an application there and then send some commands to this application. My idea was to do it through telnetlib
Solution 1:
you can do the following:
child = pexpect.spawn('telnet 192.168.0.1')
child.expect('[Ll]ogin') #you use the expected output, here will match either Login or login
child.sendline('username')
child.expect('[Pp]assword')
child.sendline('password')
child.expect('your remote prompt')
child.sendline('command')
you can install pexpect using pip
You can also have a list of expect:
index = child.expect['[Ll]ogin', '[Pp]assword']
ifindex == 0:
child.sendline('username')
elseindex == 1:
child.sendline('password')
Post a Comment for "Send Commands To A Remote Machine Application With Python"