Reading 'ipconfig' with Python-Pexpect
<p>I'm running freeSSHd on win XP as an SSH server and it's returning CMD shell for authenticated users, and I want to get the result of sending 'ipconfig' command automatically when I run the python script, I got the connection working but I have an issue with reading the result for each field and putting it in separate variable, the result for my code is '4' instead of '10' > first digit in IP address, I don't know where did number 4 come from. Any idea?</p>

<p>Output of Win XP ipconfig</p>

<p>C:\Documents and Settings\hussam\Desktop>ipconfig</p>

<pre><code>Windows IP Configuration


Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 10.0.2.10
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 10.0.2.15

C:\Documents and Settings\hussam\Desktop&gt;
</code></pre>

<p>My Code</p>

<pre><code>import pexpect
import re

def sendcommand(conn,command):
    conn.sendline(command)
    conn.expect('\d')
    print conn.after

def c(ip,username,password):
    global conn
    ft = 'ssh '+username+'@'+ip
    print 'we are trying to connect to ' + ft
    new = 'Are you sure you want to continue connecting'
    conn = pexpect.spawn(ft)
    result = conn.expect([ pexpect.TIMEOUT , new ,'[P|p]assword:' ])
    if result == 0:
        print 'connection error'
        return
    if result == 1:
        conn.sendline('yes')
        result = conn.expect([ pexpect.TIMEOUT , '[P|p]assword:'])
    if result == 0:
        print 'connection error'
        return
    conn.sendline(password)
    conn.expect('&gt;')
    sendcommand(conn,command)



def main ():
    global command
    username = 'hkhrais'
    ip = '10.0.2.10'
    password = 'hkhrais'
    command = ' ipconfig'
    c(ip,username,password)


 main ()
</code></pre>
