Linuxを介してhmaプロキシを実行するサブプロセスを取得しようとしています。私はPythonを初めて使用するので、正しいアプローチを使用していない可能性があります。私がする必要があるのは、バックグラウンドでhmaを実行し、パブリックIPがプログラムの起動前と同じであるかどうか、および30分ごとにhmaプログラムを再実行しないかどうかをプログラムに確認させることです。
基本的に、プログラムは現在のIPをチェックしてから、hmaに接続する必要があります。最初のIPが2番目の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
私は何が間違っているのですか?これが完全に間違っている場合は申し訳ありません。サブプロセスモジュールは初めてです