There is a software which changes its behavior based on accessibility of the Active Directory domain controller (for domain joined machines). For example, if a machine inside a LAN and the domain controller is accessible, all features are available. If the machine goes outside of the LAN, some features of the software are disabled.
It works well on Windows using the standard Win32 API but I cannot find a way to implement it for macOS so far. I could not find any API. I tried some command line tools. For example,
dscl "/Active Directory/<DOMAIN NAME>" read / dsAttrTypeNative:DomainName
odutil show nodenames
Even if I disconnect the macOS machine from the AD LAN, they still show the information for about 30 minutes, like the domain controller is still accessible.
I cannot delete the whole Open Directory AD cache to make the tools to refresh the information because the cache is used by the system and the other applications. I do not want to change behavior of the whole system. I cannot kill (restart) services for that because I need to do it quite often (every 2-5 minutes).
I know I can use ldapsearch (or an LDAP C++ library) to check accessibility of an AD domain controller but my software does not have any idea about the domain controller configuration. It does not have any credentials to request the information. Also, in case of Windows API, Kerberos is used by default. In case of ldapsearch it has to be configured.
So, is there any macOS API (Objective C, C++) or any system command tool which I can use without additional configuration to check if the AD domain controller is accessible?