Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Get IP address of computer (MFC/VC++)

Get IP address of computer (MFC/VC++)

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiotutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    waxie
    wrote on last edited by
    #1

    Hi, Could you provide me a code snippet on how to acquire the IP address of the computer? I'm not using .NET just a pure visual c++ IDE. I just want to get the ip address of my computer and store it in a string. If you could give me an idea on how to do that without using the .NET environment, I'd really appreciate it very much.:-O Thanks, Christina J.

    J E 2 Replies Last reply
    0
    • W waxie

      Hi, Could you provide me a code snippet on how to acquire the IP address of the computer? I'm not using .NET just a pure visual c++ IDE. I just want to get the ip address of my computer and store it in a string. If you could give me an idea on how to do that without using the .NET environment, I'd really appreciate it very much.:-O Thanks, Christina J.

      J Offline
      J Offline
      JonEngle
      wrote on last edited by
      #2

      Look up GetIpAddrTable in MSDN.

      1 Reply Last reply
      0
      • W waxie

        Hi, Could you provide me a code snippet on how to acquire the IP address of the computer? I'm not using .NET just a pure visual c++ IDE. I just want to get the ip address of my computer and store it in a string. If you could give me an idea on how to do that without using the .NET environment, I'd really appreciate it very much.:-O Thanks, Christina J.

        E Offline
        E Offline
        eli15021979
        wrote on last edited by
        #3

        Hi, IS this what yoo are looking for?

        struct hostent \*Host;
        SIZE\_T t=100;
        CString szIP , szName;
        char \*host\_name = new char\[100\];
        
        gethostname(host\_name,t);
        Host = gethostbyname(host\_name);
        szName = host\_name;
        szIP = inet\_ntoa(\*((struct in\_addr\*)Host->h\_addr));
        delete \[\]host\_name;
        

        Regards, Eli

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups