Get local IP from LocalEndPoint

sgt_pinky
03-30-2004, 08:52 PM
Heya,

In my VB6 app I had: my_ip = Winsock1.LocalIP

Now I need the .Net equivalent to this. I have fixed all my other Winsock API stuff would you believe, but I can't work out this simple problem!! hahaha

I have searched MSDN, and adapted what they had to get the following, but it doesnt work. I think maybe because the socket isnt connected?? But I only want the local IP. There must be an easier way.


Dim tcpSocket As New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
MsgBox(Net.IPAddress.Parse(CType(tcpSocket.LocalEndPoint, Net.IPEndPoint).Address.ToString()))

sgt_pinky
03-30-2004, 09:14 PM
Worry not, I have the solution:


Dim myIPHE As Net.IPHostEntry = Net.Dns.GetHostByName(Net.Dns.GetHostName.ToString)
Dim myIP() As Net.IPAddress = myIPHE.AddressList
MY_IP_ADDRESS = myIP(0).ToString


The array myIP gives you all IP addresses associated with that computer. Eg: modem connection, local connection etc. I just index zero, because I only use this for licensing anyway.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum