2010-08-05 3 views

답변

2

에서 gethostname

는 gethostbyname까지도 특정 이름으로 호스트를 외모와 주소 당신에게

man 3 gethostname 
man 3 gethostbyname 

을 줄 것이다 또는 당신이 정보를 추출 할 수 있습니다 당신에게 현재 호스트의 이름을 줄 것이다 다음과 같이 시스템에서 필요합니다.

#include <cstdlib> 
#include <iostream> 
#include <fstream> 

int main(){ 
    system("ifconfig -a | grep inet | " 
     "sed 's/\\([ ]*[^ ]*\\)\\([ ]*[^ ]*\\).*$/\\1 \\2/' " 
     " > networkinfos.txt") ; 
} 
+1

두 번째 아이디어는 POSIX 시스템을 가정합니다. gethostname/gethostbyname도 Windows에서 작동합니다. – MSalters

관련 문제