Extension Attribute returning no results...

chappj01
New Contributor

I've written an extension attribute to pull a list of the search domains set for all of the Wi-Fi, AirPort, or Ethernet connections on a system. It works perfect if I run it from the command line, but for the life of me, I can't figure out why it's not returning any results whatsoever when I run a recon. Here's the code...

#!/usr/bin/python

import os
import sys

# Let's figure out which network connections we have.  We're only looking for Ethernet and Wi-Fi connections.
p = os.popen('/usr/sbin/networksetup -listallnetworkservices | grep -e Ethernet -e Wi-Fi -e AirPort').read()
p = p.strip().split('
')


domains = "<result>"
for i in p:
    s = os.popen('/usr/sbin/networksetup -getsearchdomains ' + '"' + i + '"').read().replace('
', ' ')
    domains = domains + i + ': ' + s
domains = domains.rstrip(' ') + "</result>"
sys.stdout.write(domains)

The output (which definitely goes to stdout - I switched to sys.stdout.write over print just to make extra sure...) looks like this when run at the terminal:
<result>Thunderbolt Ethernet: domain1.com domain2.com Display Ethernet: domain1.com domain2.com Wi-Fi: domain1.com domain2.com</result>

Hopefully I'm just missing something blindingly obvious.

0 REPLIES 0