How would one output your IP and hostname?
Printable View
How would one output your IP and hostname?
cout << "127.0.0.1 localhost" << endl;Quote:
Originally posted by Nakeerb
How would one output your IP and hostname?
he speaks the truth.Quote:
Originally posted by moi
cout << "127.0.0.1 localhost" << endl;
I meant using Winsock
That's the loopback address on any computer.
Code:
char * local_host_info(char buffer[]) {
int index = 0;
const int max = 200;
char local[max];
hostent * find;
int result;
buffer[0] = 0;
strcat( buffer, "Local host name: " );
result = gethostname( local, max );
find = gethostbyname( local );
if( !find || result == SOCKET_ERROR ) {
strcat( buffer, "Information not Available.\n" );
return buffer;
}
strcat( buffer, local );
while( find->h_addr_list[ index ] ) {
strcat( buffer, "\n" );
strcat( buffer, inet_ntoa( *(in_addr*)find->h_addr_list[ index++ ] ) );
}
return strcat( buffer, "\n\n\n");
}
int main() {
char buff[256]
//...initialize winsock...
printf("My info \n\n%s", local_host_info( buff ));
return 0;
}