だから私は、リモートサーバーにsshして、その端のiperfサーバーを起動するプログラムを持っています。それが実行されると、クライアント側からそのサーバーを iperf します。
たとえば、静的に IP アドレスを指定すると正常に動作します。
p=pexpect.spawn('ssh -t -x paddy@20.20.20.20 ' + iperf)
しかし、私が使用するときではありません:
p=pexpect.spawn('ssh -t -x paddy@'+ADDRESS+' ' + iperf)
私は得る:
'pexpect.TIMEOUT'
ADDRESS は間違いなく正しく入っています。何がうまくいかないかについて何か考えがありますか?
#!/usr/bin/env python
import pexpect
import re
import shutil
import getpass
import struct, fcntl, os, sys, signal, time
def start_Server(iperf, password, ADDRESS):
ssh_newkey = 'Are you sure you want to continue connecting'
fix = ADDRESS+' ' + iperf
p=pexpect.spawn('ssh -t -x paddy@'+ fix)
i=p.expect([ssh_newkey,'password:',pexpect.EOF,pexpect.TIMEOUT],1)
if i==0:
print "I say yes"
p.sendline('yes')
i=p.expect([ssh_newkey,'password:',pexpect.EOF])
if i==1:
pwtp = False
trysout = True
while pwtp == False:
trysout = True
p.sendline(password)
loginStuff=p.expect(['Permission denied, please try again.','Permission denied (publickey,password).', '------------------------------------------------------------', pexpect.TIMEOUT,pexpect.EOF],1)
if loginStuff == 0:
password = getpass.getpass("Please enter "+ADDRESS+"'s Password")
elif loginStuff == 1:
print 'Sorry but you faild to login'
sys.exit(0)
pwtp = True
trysout = False
elif loginStuff == 2:
pwtp = True
i=3
elif loginStuff == 4:
pwtp = True
pass
else:
pass
elif i==2:
print "I either got key or connection timeout"
pass
elif i==4:
print "I either got key or connection timeout"
pass
if i==3: #timeout
print fix
print ADDRESS
print 'we find outselfs in a timeout'
print i
pass
return p, password
def RepresentsInt(s):
try:
int(s)
return True
except ValueError:
return False
var = raw_input("Enter the destination IP address: ")
ADDRESS = var
password = getpass.getpass("Please enter "+ADDRESS+"'s Password")
t, password = start_Server('iperf -s', password, ADDRESS)
u, password = start_Server('iperf -u -s', password, ADDRESS)
print ADDRESS
p=pexpect.spawn('ssh -t -x paddy@20.20.20.20 iperf -u -s')
ssh_newkey = 'Are you sure you want to continue connecting'
i=p.expect([ssh_newkey,'password:',pexpect.EOF])
if i == 0:
print ssh_newkey
elif i == 1:
print 'password:'
elif i == 2:
print pexpect.EOF
else:
print 'Sorry what!?'
print i