Link to home
Start Free TrialLog in
Avatar of radek_s
radek_s

asked on

My IP address

While I connect to Internet by Dial-up
modem connection, how can I get my IP
ADDRESS and HostName?
ASKER CERTIFIED SOLUTION
Avatar of naveenkohli
naveenkohli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NT_Programmer
NT_Programmer

Here's some code that does exactly that:

      CString m_IPAddress; // holds the numeric dotted address
      CString m_IPName; // holds the computer name.


      char pszname[ 0x40 ];
      ::gethostname( pszname, sizeof( pszname ) );
      hostent* ph = ::gethostbyname( pszname );
      m_IPName = ph->h_name;
      unsigned u = *( (unsigned*) ( ph->h_addr_list[ 0 ] ) );
      m_IPAddress.Format( "%d.%d.%d.%d", ( u ) & 0x000000ff, ( u >> 8 ) & 0x000000ff, ( u >> 16 ) & 0x000000ff, ( u >> 24 ) & 0x000000ff );