如何以编程方式查找计算机的域

How to find the computer's domain programatically

本文关键字:计算机 查找 方式 编程      更新时间:2023-10-16

目前大多数系统都连接到一个域左右。我可以进行任何方法/系统调用来获取系统当前域(类似于 gethostname 的东西)。我主要在寻找一些便携式解决方案(win/Lin),但如果你能指导我如何在 Linux 中获取信息,这将非常有帮助。我正在尝试在 Linux 的C++程序中获取相同的内容,但尚未能够。

澄清一下,我知道我们可以轻松获得主机名。它是我正在寻找的"localhost@somedomain"的"某个域"部分。

有一个

getdomainname()函数,它获取您计算机的DNS域名(不是工作组/Windows域),例如:

#include <iostream>
#include <unistd.h>
int main() {
  char buffer[1024];
  getdomainname(buffer, sizeof(buffer));
  std::cout << buffer << std::endl;
}