Outputting your IP and hostname

This is a discussion on Outputting your IP and hostname within the C++ Programming forums, part of the General Programming Boards category; How would one output your IP and hostname?...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    155

    Outputting your IP and hostname

    How would one output your IP and hostname?

  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946

    Re: Outputting your IP and hostname

    Originally posted by Nakeerb
    How would one output your IP and hostname?
    cout << "127.0.0.1 localhost" << endl;
    hello, internet!

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718

    Re: Re: Outputting your IP and hostname

    Originally posted by moi
    cout << "127.0.0.1 localhost" << endl;
    he speaks the truth.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    I meant using Winsock

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,439
    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;
    }
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting ip by hostname
    By NiSA in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-26-2007, 10:56 PM
  2. obtain hostname or IP
    By afisher in forum Networking/Device Communication
    Replies: 3
    Last Post: 12-01-2004, 06:46 AM
  3. ip or hostname
    By jchanwh in forum C Programming
    Replies: 2
    Last Post: 04-08-2002, 08:41 PM
  4. Resolving Hostname :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-08-2002, 08:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21