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 can i get the ip addres of host on windows application

how can i get the ip addres of host on windows application

Scheduled Pinned Locked Moved C#
question
8 Posts 4 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.
  • S Offline
    S Offline
    sa_keles
    wrote on last edited by
    #1

    i am trying to get the ip address of host on windows application thanks openup your heart and let the sun shine in :)

    S M J 3 Replies Last reply
    0
    • S sa_keles

      i am trying to get the ip address of host on windows application thanks openup your heart and let the sun shine in :)

      S Offline
      S Offline
      Steve Pullan
      wrote on last edited by
      #2

      Try these search terms in The Code Project search... ip address of host You will find plenty of hits. One of them is bound to do what you want or at the very least point you in the right direction. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

      S 1 Reply Last reply
      0
      • S Steve Pullan

        Try these search terms in The Code Project search... ip address of host You will find plenty of hits. One of them is bound to do what you want or at the very least point you in the right direction. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-) (Translation: I'll show you the way, but not write the code for you.)

        S Offline
        S Offline
        sa_keles
        wrote on last edited by
        #3

        thanks for your reply Steve , i'll learn to fish :) openup your heart and let the sun shine in :)

        1 Reply Last reply
        0
        • S sa_keles

          i am trying to get the ip address of host on windows application thanks openup your heart and let the sun shine in :)

          M Offline
          M Offline
          mcljava
          wrote on last edited by
          #4

          Pretty simple if you are programming with sockets. If TCP, then you can refer to the IPEndPoint object after establising a connection OR accepting one. If UDP, each message is self identifying so you can extract the Host IP from the header. If you problem is not covered by Socket Programming, then let me know. Also there are about a zillion examples of TCP and UDP client between this site and if u google the net. Good luck Mike Luster CTI/IVR/Telephony SME

          S 1 Reply Last reply
          0
          • S sa_keles

            i am trying to get the ip address of host on windows application thanks openup your heart and let the sun shine in :)

            J Offline
            J Offline
            jklucker
            wrote on last edited by
            #5

            If you are referring to the local PC as host you could use WMI to retrieve the IP address. using System.Management public ArrayList ActiveIP() { ObjectQuery oq = new ObjectQuery("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=true"); ManagementObjectSearcher mos = new ManagementObjectSearcher(oq); ArrayList NA = new ArrayList(); foreach(ManagementObject moInfo in mos.Get()) { string[] IP = (string[])moInfo["IPAddress"]; NA.Add(IP.GetValue(0).ToString()); } return NA; } This will return all the IP address the PC has. Hope this helps! I reject your reality and substitute my own! - Adam Savage, Mythbuster -George W Bush life is like a roll of toilet paper. The closer it gets to the end, the faster it goes. My definition of an expert in any field is a person who knows enough about what's really going on to be scared. - PJ Plauger

            S 2 Replies Last reply
            0
            • M mcljava

              Pretty simple if you are programming with sockets. If TCP, then you can refer to the IPEndPoint object after establising a connection OR accepting one. If UDP, each message is self identifying so you can extract the Host IP from the header. If you problem is not covered by Socket Programming, then let me know. Also there are about a zillion examples of TCP and UDP client between this site and if u google the net. Good luck Mike Luster CTI/IVR/Telephony SME

              S Offline
              S Offline
              sa_keles
              wrote on last edited by
              #6

              thanks for your reply Mike, i found this code String strHostName = Dns.GetHostName(); // Find host by name IPHostEntry iphostentry = Dns.GetHostByName(strHostName); // Grab the first IP addresses String IPStr = ""; foreach(IPAddress ipaddress in iphostentry.AddressList) { IPStr = ipaddress.ToString(); } i am trying to do a chat program(socket programming it is my homework client send message to another client through the server) my time is over tomorrow ,unfortunately i couldnt fnish but i liked very much socket programming and i will search about, is there any article about socket programming you advise openup your heart and let the sun shine in :)

              1 Reply Last reply
              0
              • J jklucker

                If you are referring to the local PC as host you could use WMI to retrieve the IP address. using System.Management public ArrayList ActiveIP() { ObjectQuery oq = new ObjectQuery("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=true"); ManagementObjectSearcher mos = new ManagementObjectSearcher(oq); ArrayList NA = new ArrayList(); foreach(ManagementObject moInfo in mos.Get()) { string[] IP = (string[])moInfo["IPAddress"]; NA.Add(IP.GetValue(0).ToString()); } return NA; } This will return all the IP address the PC has. Hope this helps! I reject your reality and substitute my own! - Adam Savage, Mythbuster -George W Bush life is like a roll of toilet paper. The closer it gets to the end, the faster it goes. My definition of an expert in any field is a person who knows enough about what's really going on to be scared. - PJ Plauger

                S Offline
                S Offline
                sa_keles
                wrote on last edited by
                #7

                thanks for your reply jklucker openup your heart and let the sun shine in :)

                1 Reply Last reply
                0
                • J jklucker

                  If you are referring to the local PC as host you could use WMI to retrieve the IP address. using System.Management public ArrayList ActiveIP() { ObjectQuery oq = new ObjectQuery("Select * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=true"); ManagementObjectSearcher mos = new ManagementObjectSearcher(oq); ArrayList NA = new ArrayList(); foreach(ManagementObject moInfo in mos.Get()) { string[] IP = (string[])moInfo["IPAddress"]; NA.Add(IP.GetValue(0).ToString()); } return NA; } This will return all the IP address the PC has. Hope this helps! I reject your reality and substitute my own! - Adam Savage, Mythbuster -George W Bush life is like a roll of toilet paper. The closer it gets to the end, the faster it goes. My definition of an expert in any field is a person who knows enough about what's really going on to be scared. - PJ Plauger

                  S Offline
                  S Offline
                  sa_keles
                  wrote on last edited by
                  #8

                  thanks jklucker i have resolved the problem openup your heart and let the sun shine in :)

                  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