开发者

Retrieving Mac OS X Proxy IP address

开发者 https://www.devze.com 2023-03-09 07:37 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号