473,413 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Get pexpect to work

Hi all,
For my first script, I'm trying to build a program to set up a vpn
connection. I'm using pexpect to handle this, but I can't get it to work.
The sendline() is causing troubles. I tested it in the interactive promt,
with these results:
>>import pexpect
child = pexpect.spawn("vpnc-connect tudelft\ nopass.conf")
child.expect(".* password .*: ")
0
>>child.sendline("[here_my_password]")
7

After this peace of code, I don't have a vpn connection. A "child.logfile
= sys.stdout" gave the information that after the spawn, vpnc was asking
for a password. I'm sure my password was correct, but my outside ip address
hasn't been changed (what should be with this connection) and there was no
vpnc process running.

What's going wrong?

Thanks in advance,
Jurian Sluiman
Oct 29 '06 #1
2 1768
Ok, somebody helped my and found with "help(child.sendline)" that the
number (7) is the number of characters from my password.

Still there doesn't seem to be that anything strange is happening. With
the logfile printed out, I found that child.expect places a 0 behind the
next rule. Is this always what's happening? And is that 0 causing all my
troubles?

I'm a newbie with python, so I don't know much about it. This is (again)
the output, but with a sys.stdout line between it:
>>child = pexpect.spawn("vpnc-connect tudelft\ nopass.conf")
child.logfile = sys.stdout
child.expect(".* password .*: ")
Enter password for wb*******@luchtbrug.tudelft.nl: 0
>>child.sendline("[my_password]")
7

Any help is really appreciated! I can search on the Internet, but with no
clue to search for and which keywords to use, all results don't help me.

Thanks,
Jurian

PS. Sorry for my bad English, I hope you can understand it.
Oct 29 '06 #2

Jurian Sluiman wrote:
Ok, somebody helped my and found with "help(child.sendline)" that the
number (7) is the number of characters from my password.

Still there doesn't seem to be that anything strange is happening. With
the logfile printed out, I found that child.expect places a 0 behind the
next rule. Is this always what's happening? And is that 0 causing all my
troubles?

I'm a newbie with python, so I don't know much about it. This is (again)
the output, but with a sys.stdout line between it:
>child = pexpect.spawn("vpnc-connect tudelft\ nopass.conf")
child.logfile = sys.stdout
child.expect(".* password .*: ")
Enter password for wb*******@luchtbrug.tudelft.nl: 0
>child.sendline("[my_password]")
7

Any help is really appreciated! I can search on the Internet, but with no
clue to search for and which keywords to use, all results don't help me.

Thanks,
Jurian

PS. Sorry for my bad English, I hope you can understand it.
I use a slightly different approach for starting vpnc-connect if that
will help:
1. have your script create a temporary vpnc configuration file
(including your password):
f1=open('/tmp/vpn.conf', 'w')
f1.write('IPSec gateway ' + vpnAddress + '\n')
f1.write('IPSec ID ' + vpnGroup + '\n')....etc.
2. create a temporary results file, such as f2 =
open('/tmp/vpncResults.txt', 'w')
3. start the vpn client: p = subprocess.Popen('/usr/sbin/vpnc-connect
/tmp/vpn.conf', shell=True, stdout=f2).stdout
4. poll the results file to determine whether or not the connection
succeeded
5. delete the temporary configuration file

Creating a temporary configuration file keeps my password out of clear
text other than for the few seconds the configuration file lives on my
hard drive. In reality, my program runs within the Twisted event-driven
framework, so I just create a deferred object when invoking
vpnc-connect and wait for the callback to see if the connection was
successful, but an earlier incarnation of my program worked with the
above code.

Oct 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrei | last post by:
Hi, I'm at a crucial stage in the development of a wide area (multi-host) ssh wrapper, and need to control what happens when a host requires password authentication. After installing pexpect,...
2
by: Michael Surette | last post by:
I have been trying to automate the changing of passwords using python and pexpect. I wrote a script as a test and it works, except that it gives me an exception when it stops running: Exception...
2
by: Adrian Casey | last post by:
I have a collection of tcl expect scripts which I am converting to python using the excellent pexpect module (http://pexpect.sourceforge.net/). So far I've had great success in getting all my...
1
by: Baillargeon, Sonny | last post by:
I am trying to use a pexpect script using python v2.3.4 with pexpect module .999 on Solaris 8. I try to execute this script. #!/usr/bin/env python '''This runs "ls -l" on a remote host using...
5
by: half.italian | last post by:
Hi all. I try not to post until I am stuck in hole with no way out. I fought with this for several hours, and am currently in the hole. I'm doing a proof of concept for creating afp shares...
1
by: Kevin Erickson | last post by:
Hello, I am attempting to use pexpect in python to copy files from a server using scp; the copy works however exceptions are thrown and it exits unsuccessfully. Below is the a sample code and...
8
by: asgarde | last post by:
hello, I'm new in Python and i would like to use Pexpect to execute a root command (i want to mount via a Pyhton script a drive) so that's my script for the moment : from os import *...
5
by: crybaby | last post by:
I need to ssh into a remote machine and check if mytest.log file is there. I have setup ssh keys to handle login authentications. How do I determine if mytest.log is there by using Pexpect. What...
2
by: BlackjadeLin | last post by:
I'm new to python I want to write a simple script to switch user,for example,from user_A to user_B. This my codes: #!/usr/bin/python import pexpect import os passwd="user_B" child =...
3
by: Karim Bernardet | last post by:
Hi I am using pexpect to do ssh tunneling and to open a vnc server (jobs on a grid cluster). When the job is canceled, these 2 processes remain on the worker node (they are detached), so I have...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.