我想编写一个C ++代码来获取有关所有主机名的完整信息,以及已添加到域控件中的计算机的IP地址和子网掩码。
gethostname will give you the name of the current host
gethostbyname looks up the host with a particular name and will give you the address
man 3 gethostname
man 3 gethostbyname
Or you can extract the information you need from the system like this :
#include <cstdlib>
#include <iostream>
#include <fstream>
int main(){
system( "ifconfig -a | grep inet | "
"sed 's/\\([ ]*[^ ]*\\)\\([ ]*[^ ]*\\).*$/\\1 \\2/' "
" > networkinfos.txt" ) ;
}
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.