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#
  4. How to get the client IP address?

How to get the client IP address?

Scheduled Pinned Locked Moved C#
questiontutorial
2 Posts 2 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.
  • K Offline
    K Offline
    Khoramdin
    wrote on last edited by
    #1

    Hello everyone, I am trying to get the IP Address of the client so the application can hook itself up to it. I am using the following code:

        private void MyApplicationForm\_Load(object sender, EventArgs e)
        {
            string strIP = null;
    
            IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName()));
            if (HosyEntry.AddressList.Length > 0)
            {
                foreach (IPAddress ip in HosyEntry.AddressList)
                {
                    strIP = ip.ToString();
                    cmbInterfaces.Items.Add(strIP);
                }
            }            
        }
    

    When I run the application on my PC which is connected via a cable to a routher I only get on IP address which is the internal IP address. But when I run the Application on my laptop which is using Wireless Connection to the same routher I get list of few IP addresses. Can someone tell me why this is the case and how can I make sure I only the IP address that my laptop is set to rather than the list of the IP addresses. Thank you very much and have a great day.

    M 1 Reply Last reply
    0
    • K Khoramdin

      Hello everyone, I am trying to get the IP Address of the client so the application can hook itself up to it. I am using the following code:

          private void MyApplicationForm\_Load(object sender, EventArgs e)
          {
              string strIP = null;
      
              IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName()));
              if (HosyEntry.AddressList.Length > 0)
              {
                  foreach (IPAddress ip in HosyEntry.AddressList)
                  {
                      strIP = ip.ToString();
                      cmbInterfaces.Items.Add(strIP);
                  }
              }            
          }
      

      When I run the application on my PC which is connected via a cable to a routher I only get on IP address which is the internal IP address. But when I run the Application on my laptop which is using Wireless Connection to the same routher I get list of few IP addresses. Can someone tell me why this is the case and how can I make sure I only the IP address that my laptop is set to rather than the list of the IP addresses. Thank you very much and have a great day.

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! I think you have a basic misconception here: Any given PC doesn't have "the one IP address", it all depends on the network connections you have. Worst case: No network at all, so the PC doesn't have an IP address at all. In all the other cases, each network interface can (and usually will) have a different IP address. Try opening a command shell and executing "ipconfig /all", you'll see the settings and IP addresses for all the network interfaces.

      Regards, mav -- Black holes are the places where God divided by 0...

      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