简体   繁体   English

如何使用C在Linux中获取系统代理设置

[英]How to get the system proxy settings in Linux using c

如何使用C或C ++在Linux中读取系统代理设置值

您正在寻找此功能getenv ("http_proxy")

System proxy settings are generally stored in environment variables like HTTP_PROXY, HTTPS_PROXY etc. 系统代理设置通常存储在HTTP_PROXY,HTTPS_PROXY等环境变量中。

'C' allows us to read enrolment variables via adding an extra argument envp to the main() function as shown. 如图所示,“ C”使我们可以通过向main()函数添加一个额外的参数envp来读取注册变量。

    int main (int argc, char *argv[], char *envp[])
    {
      char *http_proxy, *https_proxy;
      http_proxy = getenv("HTTP_PROXY");
      https_proxy = getenv("HTTPS_PROXY");
      printf ("Proxy settings :: %s on %s.\n", http_proxy, https_proxy);
      return 0;
    }

This should do the trick depending on what variables you would want to process. 这应该根据您要处理的变量来解决。

Most Linux distributions that I've seen do not have the notion of a "system proxy". 我见过的大多数Linux发行版都没有“系统代理”的概念。 The desktop environments that run on top of Linux (KDE, Gnome, etc....) generally have configuration options to set up a proxy, which most applications written for that desktop will then have access to, but how to look that up in code will be different depending on which environment you're running. 运行在Linux之上的桌面环境(KDE,Gnome等)通常具有用于设置代理的配置选项,然后为该桌面编写的大多数应用程序都可以访问该代理,但是如何在其中查找根据您所运行的环境,代码会有所不同。 Also, running eg KDE apps under Gnome or vice versa may not get the same results, unless both have been configured properly. 同样,在Gnome下运行(例如反之亦然)运行KDE应用程序可能不会获得相同的结果,除非已正确配置了两者。 Because of this and a number of other things, many individual applications have their own way to set proxies. 因此,许多其他应用程序都有自己的设置代理的方法。 One of those possible ways, that works for some applications is the environment variables mentioned in other answers (other possibilities being various configuration files, or connecting to one of the configuration services like gconf). 适用于某些应用程序的那些可能方式之一是其他答案中提到的环境变量(其他可能性是各种配置文件,或连接到诸如gconf之类的配置服务之一)。 If you're writing a new app and just want to be able to set and use a proxy in that app, this approach is probably one of the simplest. 如果您正在编写一个新应用程序,并且只希望能够在该应用程序中设置和使用代理,则此方法可能是最简单的方法之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Linux 中使用 C/C++ 和 system() 系统调用以外的其他方法获取文件功能? - How to get file capabilities in Linux using C/C++ with other method than system() system call? C++ REST SDK (Casablanca) - 如何获取 HTTP 代理设置 - C++ REST SDK (Casablanca) - How to get HTTP Proxy settings 如何使用C / C ++系统调用获取Linux中进程的堆内存的当前大小? - How do I get the current size of the heap memory of a process in Linux using C/C++ system calls? 如何使用Qt获取系统代理? - How do I get the system proxy using Qt? 如何在不调用“system()”的情况下使用 C++ 或 Qt 关闭 Linux? - How to shutdown Linux using C++ or Qt without call to “system()”? 如何在Linux上使用QProcessEnvironment设置代理地址? - How to set Proxy Address using QProcessEnvironment on Linux? C Linux代理服务器 - C linux proxy server 如何快速获取 WinInet 的代理设置(不依赖网络) - How to get WinInet's proxy settings quickly (without network dependency) 如何在C / C ++中获取Linux系统调用的输出? - How do I get the output of a Linux System Call in C/C++? 如何在Linux中使用c或c ++而不使用system()或exec()函数的情况下调用pwd或ls -l之类的系统函数? - how we can call a system function like pwd or ls -l without using system() or exec() function using c or c++ in linux?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM