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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting IP and Language

Getting IP and Language

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 3 Posters 1 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.
  • X Offline
    X Offline
    xxhimanshu
    wrote on last edited by
    #1

    :confused:Hi all, I am in desperate need to know the dynamic IP allocated to a user when he browses by the ISP, also I want to know the Browser Language..can anyone show me some pointers or ideas or tutorials to do this..any sort of help is highly appreciated...Thanks a lot in advance... Himanshu

    W 1 Reply Last reply
    0
    • X xxhimanshu

      :confused:Hi all, I am in desperate need to know the dynamic IP allocated to a user when he browses by the ISP, also I want to know the Browser Language..can anyone show me some pointers or ideas or tutorials to do this..any sort of help is highly appreciated...Thanks a lot in advance... Himanshu

      W Offline
      W Offline
      Will Beattie
      wrote on last edited by
      #2

      Here is a code snippet that may be called more than once. The first time will return how many NET I/O addresses are available, a second call may nominate which of the available IP addresses to return. Hope this helps... cheers WillB //***************************************************************** //** ** //** ** //** ** //** G E T H O S T N A M E ** //** ** //** ** //** ** //***************************************************************** int MNF_GetHostIPAddress( CString & rszHostName, CString &rszHostIPAddress, int nIPSelection) { int nIPCount = 0; in_addr **papIPAddressList; HOSTENT *ptHostEnt = NULL; rszHostIPAddress = ""; // ---> ----------------------- <--- // ---> Discover IP address(es) <--- // ---> ----------------------- <--- ptHostEnt = gethostbyname( rszHostName ); if ( ptHostEnt != NULL ) { papIPAddressList = (in_addr **)&ptHostEnt->h_addr_list[ 0 ]; // ---> ----------------------- <--- // ---> Count the IP Addressess <--- // ---> ----------------------- <--- while ( papIPAddressList[ nIPCount ] != NULL ) { nIPCount++; } if ( nIPSelection < nIPCount ) { rszHostIPAddress = inet_ntoa( *papIPAddressList[ IPSelection ] ); } } return nIPCount; }

      X 1 Reply Last reply
      0
      • W Will Beattie

        Here is a code snippet that may be called more than once. The first time will return how many NET I/O addresses are available, a second call may nominate which of the available IP addresses to return. Hope this helps... cheers WillB //***************************************************************** //** ** //** ** //** ** //** G E T H O S T N A M E ** //** ** //** ** //** ** //***************************************************************** int MNF_GetHostIPAddress( CString & rszHostName, CString &rszHostIPAddress, int nIPSelection) { int nIPCount = 0; in_addr **papIPAddressList; HOSTENT *ptHostEnt = NULL; rszHostIPAddress = ""; // ---> ----------------------- <--- // ---> Discover IP address(es) <--- // ---> ----------------------- <--- ptHostEnt = gethostbyname( rszHostName ); if ( ptHostEnt != NULL ) { papIPAddressList = (in_addr **)&ptHostEnt->h_addr_list[ 0 ]; // ---> ----------------------- <--- // ---> Count the IP Addressess <--- // ---> ----------------------- <--- while ( papIPAddressList[ nIPCount ] != NULL ) { nIPCount++; } if ( nIPSelection < nIPCount ) { rszHostIPAddress = inet_ntoa( *papIPAddressList[ IPSelection ] ); } } return nIPCount; }

        X Offline
        X Offline
        xxhimanshu
        wrote on last edited by
        #3

        :confused:Thanks for the code snippet..but I guess it doesnt work properly, as we will have to pass some arguments..I dont want to pass any prguments into it and want to know the IP address of the machine assigned by the ISP. Not the local IP I can do that. How to get the ISP provided IP. Please help.Any help or pointers are appreciated.. Thanks in advance. Himanshu

        B 1 Reply Last reply
        0
        • X xxhimanshu

          :confused:Thanks for the code snippet..but I guess it doesnt work properly, as we will have to pass some arguments..I dont want to pass any prguments into it and want to know the IP address of the machine assigned by the ISP. Not the local IP I can do that. How to get the ISP provided IP. Please help.Any help or pointers are appreciated.. Thanks in advance. Himanshu

          B Offline
          B Offline
          Baris Kurtlutepe
          wrote on last edited by
          #4

          The "IP Helper API" is the keyword you're looking for and here's a snippet of the code that I've written to gather all IP addresses assigned to the system:

          ULONG adpsize = 32768; // a little generous :p
          void* adpinf = malloc(adpsize);
          if (GetAdaptersInfo((PIP_ADAPTER_INFO) adpinf, &adpsize) == ERROR_SUCCESS)
          {
          PIP_ADAPTER_INFO pip = (PIP_ADAPTER_INFO) adpinf;
          while (pip)
          {
          PIP_ADDR_STRING ips = &pip->IpAddressList;
          while (ips)
          {
          // use ips->IpAddress.String here
          ips = ips->Next;
          }
          pip = pip->Next;
          }
          }
          free(adpinf);

          Regarding your question about the language of the OS you can use GetSystemDefaultLangID from the Win32 API, if I understood your question correctly.

          X 1 Reply Last reply
          0
          • B Baris Kurtlutepe

            The "IP Helper API" is the keyword you're looking for and here's a snippet of the code that I've written to gather all IP addresses assigned to the system:

            ULONG adpsize = 32768; // a little generous :p
            void* adpinf = malloc(adpsize);
            if (GetAdaptersInfo((PIP_ADAPTER_INFO) adpinf, &adpsize) == ERROR_SUCCESS)
            {
            PIP_ADAPTER_INFO pip = (PIP_ADAPTER_INFO) adpinf;
            while (pip)
            {
            PIP_ADDR_STRING ips = &pip->IpAddressList;
            while (ips)
            {
            // use ips->IpAddress.String here
            ips = ips->Next;
            }
            pip = pip->Next;
            }
            }
            free(adpinf);

            Regarding your question about the language of the OS you can use GetSystemDefaultLangID from the Win32 API, if I understood your question correctly.

            X Offline
            X Offline
            xxhimanshu
            wrote on last edited by
            #5

            :confused:Thanks for the language thing...can you please tell the dependencies etc..i am unable to compile ur code..i used iphlpi.h and its lib file in link..but still it is not compiling and can you message the IPS issued from this code..I shall be highly obliged if u can revert back asap.. thanks in advance.. Himanshu

            B 1 Reply Last reply
            0
            • X xxhimanshu

              :confused:Thanks for the language thing...can you please tell the dependencies etc..i am unable to compile ur code..i used iphlpi.h and its lib file in link..but still it is not compiling and can you message the IPS issued from this code..I shall be highly obliged if u can revert back asap.. thanks in advance.. Himanshu

              B Offline
              B Offline
              Baris Kurtlutepe
              wrote on last edited by
              #6

              The only dependency is iphlpapi.lib which comes with Platform SDK I guess, you should download & install it if you haven't already done so. If it gives a linker error then that's the case, if not could you please paste the error lines? When I run this on my computer I get two IP addresses, cause I have two ethernet adapters: one for my LAN and one for my cable connection to the Internet. Back to your question, a dialup adapter is a virtual adapter and thus if the ISP has assigned an IP to your computer via DHCP, you should get it in that loop as well. In your case, if the host computer has more than one IP address such as mine, you should have your own way of differentiating it from the other IP addresses, such as checking for the type of the adapter, looking for a name etc... Sorry for the late response, I've been sleeping all day :-O

              X 1 Reply Last reply
              0
              • B Baris Kurtlutepe

                The only dependency is iphlpapi.lib which comes with Platform SDK I guess, you should download & install it if you haven't already done so. If it gives a linker error then that's the case, if not could you please paste the error lines? When I run this on my computer I get two IP addresses, cause I have two ethernet adapters: one for my LAN and one for my cable connection to the Internet. Back to your question, a dialup adapter is a virtual adapter and thus if the ISP has assigned an IP to your computer via DHCP, you should get it in that loop as well. In your case, if the host computer has more than one IP address such as mine, you should have your own way of differentiating it from the other IP addresses, such as checking for the type of the adapter, looking for a name etc... Sorry for the late response, I've been sleeping all day :-O

                X Offline
                X Offline
                xxhimanshu
                wrote on last edited by
                #7

                :confused:Hi, Thanks for ur sooner reply..I dont have any errors now..but I cannot understand the parameters to be passed..CString& rszHostName,CString& rszHostIPAddress, int nIPSelection..please guide.and reply soon..I shall be waiting for ur response. Thanks a ton in advance.. Himanshu

                B 1 Reply Last reply
                0
                • X xxhimanshu

                  :confused:Hi, Thanks for ur sooner reply..I dont have any errors now..but I cannot understand the parameters to be passed..CString& rszHostName,CString& rszHostIPAddress, int nIPSelection..please guide.and reply soon..I shall be waiting for ur response. Thanks a ton in advance.. Himanshu

                  B Offline
                  B Offline
                  Baris Kurtlutepe
                  wrote on last edited by
                  #8

                  Hi Himanshu, Sorry but I really don't think that I do understand. Weren't you asking for the IP address of the local computer? Now say that's the rszHostIPAddress parameter. What are the other two? :confused: You've mentioned above you needed a function which receives no parameters, now you want to pass parameters to it? The method I've described above let's you get the IP addresses assigned to a computer, note that whilst a computer has a single hostname, it can have many IP addresses. And that about nIPSelection, I really don't understand, sorry...

                  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