简体   繁体   中英

Retrieving Mac OS X Proxy IP address

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, eg HTTP proxy or HTTPS proxy. For a list of all possible proxies, see the SCSchemaDefinitions Reference .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM