iputil: use the subprocess module instead of os.popen

This commit is contained in:
Brian Warner 2007-03-07 19:29:00 -07:00
parent d4020fa533
commit eccb3258ae
1 changed files with 6 additions and 3 deletions

View File

@ -1,10 +1,10 @@
# adapted from nattraverso.ipdiscover # adapted from nattraverso.ipdiscover
import os import subprocess
from cStringIO import StringIO
import re import re
import socket import socket
from cStringIO import StringIO
from twisted.internet import reactor from twisted.internet import reactor
from twisted.internet.protocol import DatagramProtocol from twisted.internet.protocol import DatagramProtocol
from twisted.internet.utils import getProcessOutput from twisted.internet.utils import getProcessOutput
@ -18,7 +18,10 @@ def get_local_addresses():
# lines. # lines.
cmd = "/sbin/ifconfig" 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 = [] addresses = []
for line in p.readlines(): for line in p.readlines():
# linux shows: " inet addr:1.2.3.4 Bcast:1.2.3.255..." # linux shows: " inet addr:1.2.3.4 Bcast:1.2.3.255..."