我想让子进程通过linux来运行hma代理。我是Python的新手,所以也许我没有使用正确的方法。我需要做的是在后台运行hma,并让程序检查我的公共IP是否与启动程序前相同,并且是否每30分钟不重新运行hma程序。hma的python子进程
基本上程序需要检查当前IP然后连接到hma。如果第一个IP匹配第二个IP,即hma尚未连接,则打印等待。如果IP不匹配,则在30分钟内再次运行hma。这是我迄今为止的代码。
import os
import webbrowser
import time
import socket
import urllib2
import subprocess
response = urllib2.urlopen("http://automation.whatismyip.com/n09230945.asp")
internal = response.read()
print "Internal IP Address is ", internal
hma = ['cd', '/Desktop/hma', ';', './hma-start', '-r']
subprocess.Popen(hma, shell=True)
response = urllib2.urlopen("http://automation.whatismyip.com/n09230945.asp")
external = response.read()
while (internal == external):
time.sleep(1)
response = urllib2.urlopen("http://automation.whatismyip.com/n09230945.asp")
external = response.read()
print 'waiting'
while (internal != external):
print 'It changed'
hma = ['cd', '/Desktop/hma', ';', './hma-start', '-r']
subprocess.Popen(hma, shell=True)
response = urllib2.urlopen("http://automation.whatismyip.com/n09230945.asp")
external = response.read()
print "External IP Address is ", external
我在做什么错了?对不起,如果这是完全错误的。我是新来的子模块
这可以工作,但HMA完成连接后,它不会执行time.sleep(WAIT_TIME)。 – 2012-07-27 21:07:55