how can i get the ip addres of host on windows application
-
i am trying to get the ip address of host on windows application thanks openup your heart and let the sun shine in :)
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.) -
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.) -
i am trying to get the ip address of host on windows application thanks openup your heart and let the sun shine in :)
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
-
i am trying to get the ip address of host on windows application thanks openup your heart and let the sun shine in :)
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 -
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
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 :)
-
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 -
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