简体   繁体   中英

Detect the running Linux distribution at compile time and/or runtime?

I am making a program in Kali Linux, and I want to make it work only in Kali. I can use C to do it, just like :

#if defined(_WIN32) || defined(_WIN64)
   #define os_platform THISisWINDOWS

For checking if the OS of the user is windows and later in the script checking the defined variable os_platform, but I searched Google and everywhere, but I just can't find the macro for Kali Linux. If I do :

#if defined(__linux__)
   #define os_platform THISisLINUX

It can be any type of Linux, like Ubuntu, and Linuxes like those. What is the macro for Kali Linux?

There's no macro for distributions. You can only do a "sniff test" to see what distribution it is by looking in /etc for particular files, and even then it can be faked.

The reason the macros exist in the first place is because Linux is radically different from BSD and Windows, so it's a necessary distinction. The difference between Kali and Debian is pretty subjective, Kali is based on Debian. Most Linux distributions are actually quite similar as far as compilers are concerned because they all use the same kernel and headers.

Things like /etc/redhat-release are distribution specific, so look for something like that. This can't be tested as an #ifdef though, it's something you'll need to put in your configure script.

可能您可以检查/etc/issue文件中的特定发行版名称,然后使用文件指针提取确切名称,然后比较(如果是Ubuntu或Kali或任何其他Linux机器)。

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