Scripting "Exclude simple hostnames"

Chris
Valued Contributor

Hello you wizards,

is there a way to script the "exclude simple hostnames" option
in the Proxies options, preferably for all existing network locations?
Looks like networksetup doesn't do the trick.

6 REPLIES 6

sean
Valued Contributor

You'll need to use PlistBuddy to write to: /Library/Preferences/SystemConfiguration/preferences.plist

You'll need to add to:
NetworkServices:[Service Key]:Proxies

By adding:
ExcludeSimpleHostnames bool YES

Sean

vrklgn
New Contributor

I had to battle this one lately so here is the final script for that.

#!/bin/sh
####################################################################################################
# Exclude Simple Hostnames on Mac OS X by vrklgn (hello@vrklgn.net)
# 2015-03-04 
# 
# Ticks Exclude Simple Hostname on all Network Interfaces
#
# With some help from Asmus @ http://apple.stackexchange.com/ & Mattias H
####################################################################################################

#!/bin/sh
# Setting value on "SetUDIDSets" to define the "Sets" name as this will be different on each computer
SetUDIDSets=$(/usr/libexec/PlistBuddy -c "print :Sets" /Library/Preferences/SystemConfiguration/preferences.plist | perl -lne 'print $1 if /^    (S*) =/')

IFS=$'
'
    # Loops through the list of network services and sets Exclude Simple Hostnames to 1.
    for i in $(/usr/libexec/PlistBuddy -c "print :Sets:$SetUDIDSets:Network:Global:IPv4:ServiceOrder" /Library/Preferences/SystemConfiguration/preferences.plist | awk 'NR>2{ print l} {l=$0}' | perl -pe 's/^s+//');
    do

# If the setting Exclude Simple Hostnames never has been touched we need to create this
    sudo /usr/libexec/PlistBuddy -c "add :NetworkServices:$i:Proxies:ExcludeSimpleHostnames integer 1" /Library/Preferences/SystemConfiguration/preferences.plist
    sudo /usr/libexec/PlistBuddy -c "set :NetworkServices:$i:Proxies:ExcludeSimpleHostnames 1" /Library/Preferences/SystemConfiguration/preferences.plist

    echo "Exclude Simple Hostnames is now set for $i" 

    done

unset IFS
defaults read /Library/Preferences/SystemConfiguration/preferences.plist
echo "We're done!"

Chris
Valued Contributor

Holy thread resurrection Batman!

Looks nice, i'll have a look at it when i get a chance.
Thanks for sharing!

msample
Contributor II

Does this help with issues regarding constant prompts for proxy authentication under the three major web browsers (i.e.,firefox, safari, chrome) ?

rodders
New Contributor III

Oh wow. Thats some dedication.
FWIW, I had one put together from someones help on the googlegroups (which I unfortunately dont have credits for: Credit to the person that helped me):

Its a bit dirty, but did the job:

echo "list Setup:/Network/Service/[^/]+"|scutil| awk '{print $4}' | cut -c 24-59 |while read serviceid; do /usr/libexec/PlistBuddy -c "Add :NetworkServices:$serviceid:Proxies:ExcludeSimpleHostnames integer 1" /Library/Preferences/SystemConfiguration/preferences.plist ;/usr/libexec/PlistBuddy -c "Set :NetworkServices:$serviceid:Proxies:ExcludeSimpleHostnames 1" /Library/Preferences/SystemConfiguration/preferences.plist; done

Remove any carriage returns as this should be on one line for it to work.

mottertektura
Contributor

Thanks for sharing, vrklgn! Sorry to resurrect this thread again but I'm having trouble scripting this as well. I've been testing and for the most part I think it does the trick, but I do have a computer that the script isn't working on and I see this in the log:

Script result: Print: Entry, ":Sets:184140ED-D1DE-4A9D-BF88-6F3087EA02D4
D19A6A68-4B79-4468-817C-0C113E886A6E:Network:Global:IPv4:ServiceOrder", Does Not Exist
Complete.

Any ideas why it might be failing on this one?

Thanks again, this was a big help!