Automate telnet?

Dennis Voss dennis at dennis-voss.de
Mon Jul 30 12:46:40 EDT 2001


> > > I have a secure Windows telnet client I'd like to automate with a
> > > script.  So far my efforts with the popen family haven't worked.  Is
> > > this a possible task?
>
> > Doing popen in Windows is quite involved. Instead, I recommend to try
> > telnetlib directly.
>
> Thanks, but unfortunately the 'secure' aspect means I can only access the
> telnet server by using  this client. Telnetlib won't work here.

Well, then you can automate the client by sending keystrokes to the
client-window.
Don't ask me about the Python, but here are a few lines I wrote with Visual
C++:

  CString msg = "ls > /dev/null\r\n";

  for(int i = 0; i <= msg.GetLength(); i++)
   ::SendMessage(m_destHWND, WM_CHAR, msg.GetAt(i), 1L);

Notes: You can only send one char at a time (thus the for loop), you need
the window handle of the remote program (m_destHWND), adjust the '\r\n'
for your case, there is also a VK_RETURN (or was it VK_ENTER) in the WinAPI
to supprt pressing that key.

Dennis





More information about the Python-list mailing list