Get Proxy value for all network interfaces

Vincent
New Contributor II

Hi to all

i was wondering if it was possible to get proxy information (which used pac file on automatic Proxy Configuration) for each network interface (Ethernet,wifi,Usb Ethernet,...) and display results thru an extension attribute

Thanks for your help

Vincent

5 REPLIES 5

AVmcclint
Honored Contributor

try something like this:

networksetup -listallnetworkservices | grep -v "*" | while read a; do networksetup -getwebproxy $a; done

You may have to play around with the networksetup command to get exactly what you want.

May
Contributor III

If you also want to check if all the interfaces are enabled for proxy or not this is a handy EA,
thanks ! @mm2270

#!/bin/bash
# From https://jamfnation.jamfsoftware.com/discussion.html?id=13779 mm2270 Mike
# Checks each interface for proxy, answers Yes if all on, answers No if any are off (skips over missing interfaces)

validConnections=("Ethernet" "Wi-Fi" "USB Ethernet" 
"Broadcom NetXtreme Gigabit Ethernet Controller" 
"Display Ethernet"
"Thunderbolt Bridge"
"Thunderbolt Ethernet")

while read connection; do
    if [[ $(echo "${validConnections[@]}" | grep "$connection") ]]; then
        setting=$(networksetup -getautoproxyurl "$connection" | awk '/Enabled/{print $NF}')
        if [[ "$setting" == "No" ]]; then
            Disabled+=("$connection")
        elif [[ "$setting" == "Yes" ]]; then
            Enabled+=("$connection")
        fi
    fi
done < <(networksetup -listallhardwareports | awk -F': ' '/Hardware Port:/{print $NF}')

if [[ -z "${Disabled[@]}" ]]; then
    echo "<result>Yes</result>"
else
    echo "<result>No</result>"

Vincent
New Contributor II

Thanks for your help but it is not exactly what i need . To resume my need : I have a script for displaying Pac file url value :

*#!/bin/sh
/usr/sbin/networksetup -detectnewhardware

IFS=$' '

for i in $(networksetup -listallnetworkservices | tail +2 );
do
autoProxyURLLocal=/usr/sbin/networksetup -getautoproxyurl "$i" | head -1 | cut -c 6-

if [ "$autoProxyURLLocal" != "(null)" ]; then echo "<result>$autoProxyURLLocal</result>"
fi
done
unset IFS

exit 0

This script is displaying url values , but i need to display url values for each network interface in extension attributes with the name of the interface .

For example : - Ethernet = http://....Pac
- Wi-Fi = http:// ....Pac

Thanks
Vincent

mm2270
Legendary Contributor III

Hi @mainiervi Vincent - it sounds like you need to employ a bash array in your script. An array can be built up over the course of the run of the script, meaning, values can be added into it as it goes, and not lose the previous values. Right now, I think you're only getting one result, because as it loops over each interface, new results replace the previous one(s).
Technically speaking, an array isn't strictly required for this. Its possible to store values into a normal variable, but arrays lend themselves a little better for that purpose.

You can try something like this to see if it gets what you're after

#!/bin/bash

/usr/sbin/networksetup -detectnewhardware

proxyList=()

while read service; do
    autoProxyURLLocal=$(/usr/sbin/networksetup -getautoproxyurl "$service" | awk '/URL:/{print $NF}')
    if [ "$autoProxyURLLocal" != "(null)" ]; then
        proxyList+=("${service} = $autoProxyURLLocal")
    fi
done < <(networksetup -listallnetworkservices | sed '1d;/^*/d')

if [[ "${proxyList[@]}" != "" ]]; then
    echo "<result>$(printf '%s
' "${proxyList[@]}")</result>"
else
    echo "<result>No proxy URLs</result>"
fi

exit 0

Vincent
New Contributor II

Hi Mike , it works perfect :) Thanks a lot

Vincent