すべてのプロキシ情報を提供する関数はSCDynamicStoreCopyProxies()で、以下の例のように呼び出すことができます (完了したらCFRelease
、これらのオブジェクトもすべて取得する必要があります。これらはすべて CF からのものであり、直接 Cocoa オブジェクトではないためです) ):
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
CFIndex count = CFDictionaryGetCount(proxies);
NSLog(@"Number of keys is %ld", count);
NSDictionary * proxyConfiguration = (NSDictionary*) proxies;
for ( id key in proxyConfiguration.keyEnumerator ) {
NSLog(@"Pair is %@ -> %@", key, [proxyConfiguration valueForKey: key]);
}
}
return 0;
}
出力は次のようになります。
2012-11-07 16:33:57.844 network-test[6501:403] Number of keys is 12
2012-11-07 16:33:57.847 network-test[6501:403] Pair is HTTPEnable -> 1
2012-11-07 16:33:57.848 network-test[6501:403] Pair is HTTPSProxy -> 127.0.0.1
2012-11-07 16:33:57.848 network-test[6501:403] Pair is ExceptionsList -> (
"www.google.com"
)
2012-11-07 16:33:57.849 network-test[6501:403] Pair is HTTPSPort -> 8888
2012-11-07 16:33:57.850 network-test[6501:403] Pair is __SCOPED__ -> {
en1 = {
ExceptionsList = (
"www.google.com"
);
FTPPassive = 1;
HTTPEnable = 1;
HTTPPort = 8888;
HTTPProxy = "127.0.0.1";
HTTPSEnable = 1;
HTTPSPort = 8888;
HTTPSProxy = "127.0.0.1";
SOCKSEnable = 1;
SOCKSPort = 8889;
SOCKSProxy = "127.0.0.1";
};
}
2012-11-07 16:33:57.850 network-test[6501:403] Pair is HTTPProxy -> 127.0.0.1
2012-11-07 16:33:57.851 network-test[6501:403] Pair is SOCKSPort -> 8889
2012-11-07 16:33:57.852 network-test[6501:403] Pair is SOCKSProxy -> 127.0.0.1
2012-11-07 16:33:57.852 network-test[6501:403] Pair is HTTPSEnable -> 1
2012-11-07 16:33:57.853 network-test[6501:403] Pair is SOCKSEnable -> 1
2012-11-07 16:33:57.853 network-test[6501:403] Pair is HTTPPort -> 8888
2012-11-07 16:33:57.854 network-test[6501:403] Pair is FTPPassive -> 1