John
asked on
Trying to get local IP address in VB 2010 - Can't get System.Net.Dns.GetHostEntry to work like System.Net.Dns.Resolve
After 2 hours of trying to do the simplest thing (finding the ip address of the local machine) and searching and searching but getting nowhere fast, I decided to ask my question here.
Apparently, System.Net.Dns.Resolve() is obsolete and I should use System.Net.Dns.GetHostEntr y() instead.
I read that GetHostEntry() can simply be used instead of Resolve() as the paramaters and return types are the same but they're not.
Dim myHostName As String = System.Net.Dns.GetHostName ()
Dim myIPAddress As String = System.Net.Dns.Resolve(myH ostName).A ddressList (0).ToStri ng() returns "192.168.2.167" which is what I want.
BUT
Dim myIPAddress As String = System.Net.Dns.GetHostEntr y(myHostNa me).Addres sList(0).T oString() returns "fe80::112:6c34:8cc7:492d% 10" which is Greek to me.
I gave up and left it using Resolve() but was hoping that someone could show me how to do it with a non-obsolete function.
Thanks
Environment: VB.Net / Visual Studio 2010 / Windows Forms Application on Win 7 x64
Apparently, System.Net.Dns.Resolve() is obsolete and I should use System.Net.Dns.GetHostEntr
I read that GetHostEntry() can simply be used instead of Resolve() as the paramaters and return types are the same but they're not.
Dim myHostName As String = System.Net.Dns.GetHostName
Dim myIPAddress As String = System.Net.Dns.Resolve(myH
BUT
Dim myIPAddress As String = System.Net.Dns.GetHostEntr
I gave up and left it using Resolve() but was hoping that someone could show me how to do it with a non-obsolete function.
Thanks
Environment: VB.Net / Visual Studio 2010 / Windows Forms Application on Win 7 x64
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
The IPAddress returned that looks like 192.168.2.167 is your computers network address usually obtained automatically from your DHCP server/router. May I ask what your real goal is because GetHostEntry() might not be what your looking for depending on what your trying to accomplish in your application. Could you elaborate?
ASKER
I have a client app and a server app that use sockets to talk to each other across my LAN.
They talk together well.
I want to put the local IP address in the title bar of both apps
They talk together well.
I want to put the local IP address in the title bar of both apps
ASKER
Thanks. Still not sure whic IP address to use. It appears that it's the first one.
ASKER
I'm confused about there being 3 addresses in my address list. Which IP address is the one that Internet Explorer uses to browse the web?