Programming
컴퓨터의 모든 IP 주소 가져오기
좋은날
2009. 6. 12. 11:01
char szHostName[128];
if( gethostname(szHostName, 128) == 0 )
{
// Get host adresses
struct hostent * pHost;
int i;
{
// Get host adresses
struct hostent * pHost;
int i;
pHost = gethostbyname(szHostName);
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{
CString str;
int j;
{
CString str;
int j;
for( j = 0; j < pHost->h_length; j++ )
{
CString addr;
{
CString addr;
if( j > 0 )
str += ".";
str += ".";
addr.Format("%u", (unsigned int)((unsigned
char*)pHost->h_addr_list[i])[j]);
str += addr;
}
// str now contains one local IP address - do whatever you want to do with it (probably add it to a list)
TRACE(str+"\n");
}
}
char*)pHost->h_addr_list[i])[j]);
str += addr;
}
// str now contains one local IP address - do whatever you want to do with it (probably add it to a list)
TRACE(str+"\n");
}
}