From: Brian Warner Date: Thu, 8 Mar 2007 02:29:00 +0000 (-0700) Subject: iputil: use the subprocess module instead of os.popen X-Git-Url: https://git.rkrishnan.org/specifications/%5B/%5D%20/flags/htmlfontify-example.html?a=commitdiff_plain;h=eccb3258aef8131b8cfc27740c80a8da5ce131df;p=tahoe-lafs%2Ftahoe-lafs.git iputil: use the subprocess module instead of os.popen --- diff --git a/src/allmydata/util/iputil.py b/src/allmydata/util/iputil.py index f849b000..f41b3dcd 100644 --- a/src/allmydata/util/iputil.py +++ b/src/allmydata/util/iputil.py @@ -1,10 +1,10 @@ # adapted from nattraverso.ipdiscover -import os -from cStringIO import StringIO +import subprocess import re import socket +from cStringIO import StringIO from twisted.internet import reactor from twisted.internet.protocol import DatagramProtocol from twisted.internet.utils import getProcessOutput @@ -18,7 +18,10 @@ def get_local_addresses(): # lines. cmd = "/sbin/ifconfig" - p = os.popen(cmd) + #p = os.popen(cmd) + c = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE) + output = c.communicate()[0] + p = StringIO(output) addresses = [] for line in p.readlines(): # linux shows: " inet addr:1.2.3.4 Bcast:1.2.3.255..."