get-proxy-settings.sh 719 B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. # Outputs host and port for system HTTP proxy or zeroes if none or not
  3. # configured.
  4. export PATH=/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin
  5. enabled=`system_profiler SPNetworkDataType|grep "HTTP Proxy Enabled"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'} 2>/dev/null`
  6. port=`system_profiler SPNetworkDataType|grep "HTTP Proxy Port"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'} 2>/dev/null`
  7. serv=`system_profiler SPNetworkDataType|grep "HTTP Proxy Server"|awk {'sub(/^.*:[ \t]*/, "", $0); print $0;'} 2>/dev/null`
  8. if [ "$enabled" = "Yes" ]; then
  9. if [ "$serv" ]; then
  10. if [ ! "$port" ]; then
  11. port=80
  12. fi
  13. echo $serv $port
  14. else
  15. echo 0.0.0.0 0
  16. fi
  17. else
  18. echo 0.0.0.0 0
  19. fi
  20. exit 0