windows - How do I find out the browser's proxy settings? -
i writing command-line tool windows uses libcurl download files internet.
obviously, downloading doesn't work when user behind proxy server, because proxy needs configured. want keep tool simple possible however, , not have burden user having configure proxy. tool doesn't have config file, user otherwise have pass in proxy settings on every command, or set environment variable or somesuch -- way hassle.
so thought, everyone's browser set properly, proxy configured , everything. true basic user because otherwise "their internet wouldn't work".
so figure can find out whether use proxy looking @ ie's proxy settings.
how go this? more specifically:
- is there 1 set of "proxy settings" in windows, used browsers (probably ie's), or have write different routines ie, firefox, opera, etc?
- i know can read values directly out of appropriate registry locations if configured manually, work "automatically detect proxy server?" have bother option, or (almost) never used?
before people start suggesting alternatives: i'm using c, i'm limited win32 api, , really want keep using c , libcurl.
the function you're looking winhttpgetieproxyconfigforcurrentuser(), documented @ http://msdn.microsoft.com/en-us/library/aa384096(vs.85).aspx. function used firefox , opera proxy settings default, although can override them per-browser. don't that, though. right thing (which else does) ie settings , assume they're correct, since are.
here's sample of relevant logic, should adapt needs:
if( winhttpgetieproxyconfigforcurrentuser( &ieproxyconfig ) ) { if( ieproxyconfig.fautodetect ) { fautoproxy = true; } if( ieproxyconfig.lpszautoconfigurl != null ) { fautoproxy = true; autoproxyoptions.lpszautoconfigurl = ieproxyconfig.lpszautoconfigurl; } } else { // use autoproxy fautoproxy = true; } if( fautoproxy ) { if ( autoproxyoptions.lpszautoconfigurl != null ) { autoproxyoptions.dwflags = winhttp_autoproxy_config_url; } else { autoproxyoptions.dwflags = winhttp_autoproxy_auto_detect; autoproxyoptions.dwautodetectflags = winhttp_auto_detect_type_dhcp | winhttp_auto_detect_type_dns_a; } // basic flags want autoproxyoptions.fautologonifchallenged = true; // here reset fautoproxy in case auto-proxy isn't // configured url fautoproxy = winhttpgetproxyforurl( hiopen, pwszurl, &autoproxyoptions, &autoproxyinfo ); } if ( fautoproxy ) { // set proxy options libcurl based on autoproxyinfo } else { if( ieproxyconfig.lpszproxy != null ) { // ie has explicit proxy. set proxy options libcurl here // based on ieproxyconfig // // note ie gives single or double colon // proxy or bypass list, means "no proxy" } else { // there no auto proxy , no manually configured proxy } }
Comments
Post a Comment