Last active
December 23, 2015 21:59
-
-
Save davidolrik/6699572 to your computer and use it in GitHub Desktop.
Find the current active http proxy on OS X.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $networksetup = `networksetup -listnetworkserviceorder`; | |
my @network_services = map { $_ =~ s/\(\d+\)\s+//; $_ } # 3. Remove (\d+) from begining of line | |
grep { /^\(\d+\)/ } # 2. Only look at lines starting with (\d+) | |
split(/\n/,$networksetup); # 1. Split into lines | |
my $proxy_conf = ''; | |
foreach my $network_service ( @network_services ) { | |
my $webproxy_plain = `networksetup -getwebproxy "$network_service"`; | |
my $params_plain = { map { split(/:\s*/,$_,2) } split(/\n/,$webproxy_plain) }; | |
my $webproxy_secure = `networksetup -getsecurewebproxy "$network_service"`; | |
my $params_secure = { map { split(/:\s*/,$_,2) } split(/\n/,$webproxy_secure) }; | |
if ( $params_plain->{Enabled} eq 'Yes') { | |
$proxy_conf .= sprintf("export http_proxy=http://%s:%d\n", $params_plain->{Server}, $params_plain->{Port}) if $params_plain->{Server}; | |
$proxy_conf .= sprintf("export https_proxy=http://%s:%d\n",$params_secure->{Server}, $params_secure->{Port}) if $params_secure->{Server}; | |
$proxy_conf .= sprintf("export HTTP_PROXY=http://%s:%d\n", $params_plain->{Server}, $params_plain->{Port}) if $params_plain->{Server}; | |
$proxy_conf .= sprintf("export HTTPS_PROXY=http://%s:%d\n",$params_secure->{Server}, $params_secure->{Port}) if $params_secure->{Server}; | |
last; | |
} | |
} | |
print $proxy_conf if $proxy_conf; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment