title: Using Pexpect for multiple kind of devices
body: <p>I am trying to access a device from a server using python script. I am using pexpect module for the same. The device may or may not have authentication. I have written the following code but it is not working as expected. Can anyone please help?</p>
  
  <pre><code>#!/usr/local/bin/python2.7
  import pexpect
  
  child = pexpect.spawn('telnet 10.xxx.xxx.xxx')
  i = child.expect(['Username:','.*#'])
  if i==0:
      child.sendline('user')
      child.expect('Password: ')
      child.sendline('password')
  
  child.expect('.*#')
  print "true"
  </code></pre>