I want to write a C++ Code to get the full information on all the host name, and ip address and sub net mask of computer that has been added to the domain control.
Asked
Active
Viewed 4,225 times
1 Answers
2
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" ) ;
}

Kami
- 5,959
- 8
- 38
- 51
-
1The second idea assumes a POSIX system. gethostname/gethostbyname also work on Windows. – MSalters Aug 05 '10 at 12:37