I'm trying to programmatically get the proxy IP address or URL set on a system.
I found code that might work in a previous question here, but it's in Objective-C and what I am trying to use is plain C.I've tried translating that obj-开发者_如何学运维c code to C but no success.
Anyone knows how to get the system proxy in C?
Thank you
This is a C translation of that answer:
CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
if (proxies) {
CFStringRef pacURL = (CFStringRef)CFDictionaryGetValue(proxies,
kSCPropNetProxiesProxyAutoConfigURLString);
if (pacURL) {
char url[257] = {};
CFStringGetCString(pacURL, url, sizeof url, kCFStringEncodingASCII);
// do something with url
}
CFRelease(proxies);
}
It needs to be linked to two frameworks: SystemConfiguration and CoreFoundation.
Note that this code gets the URL for automatic proxy configuration (kSCPropNetProxiesProxyAutoConfigURLString
), if any. There are several other possible proxies, e.g. HTTP proxy or HTTPS proxy. For a list of all possible proxies, see the SCSchemaDefinitions Reference.
精彩评论