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 IP address of the current host?

How to get the IP address of the current host?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
6 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.
  • B Offline
    B Offline
    bouli
    wrote on last edited by
    #1

    Hi gurus, I'd like to know how to get the IPv4 address of the current host in .NET 2? Thanks. Best regards. Fred. There is no spoon.

    M D 2 Replies Last reply
    0
    • B bouli

      Hi gurus, I'd like to know how to get the IPv4 address of the current host in .NET 2? Thanks. Best regards. Fred. There is no spoon.

      M Offline
      M Offline
      mikailcetinkaya
      wrote on last edited by
      #2

      it is like ipv6= 0.0.ipv4 Mikail Çetinkaya . The C# DEveloper

      D 1 Reply Last reply
      0
      • B bouli

        Hi gurus, I'd like to know how to get the IPv4 address of the current host in .NET 2? Thanks. Best regards. Fred. There is no spoon.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You could get the host name from the DNS.GetHostName[^] method, then pass that name to the Dns.GetHostAddresses[^] method to retrieve all the IP addresses known for this host. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        B 1 Reply Last reply
        0
        • M mikailcetinkaya

          it is like ipv6= 0.0.ipv4 Mikail Çetinkaya . The C# DEveloper

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          :wtf: :confused: Whatever that means... and no, that's not how an IP6 address looks. You didn't even tell him how to resolve the name, let alone find the name of the machine. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            You could get the host name from the DNS.GetHostName[^] method, then pass that name to the Dns.GetHostAddresses[^] method to retrieve all the IP addresses known for this host. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            B Offline
            B Offline
            bouli
            wrote on last edited by
            #5

            yes, I know, this is shown in the msdn, but how to get the right address? That is the one which appears in the properties pannel of the network connection... fred. There is no spoon.

            D 1 Reply Last reply
            0
            • B bouli

              yes, I know, this is shown in the msdn, but how to get the right address? That is the one which appears in the properties pannel of the network connection... fred. There is no spoon.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              There is no "right-address". A single NIC can have multiple addresses assigned to it. This is the address that DNS servers know about. You could also get this from WMI (System.Management namespace). All you need to do is search for all the occurances of Win32_NetworkAdapterConfiguration objects. Each will have its own array of IPAddresses. Warning: You might be surprised at how many of these object and addresses there really are! Once you have those, examine them to see which ones have an active DefaultIPGateway. This will be the adapter and set of addresses that your talking about. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              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