I have found some VB .NET code on the Internet capable of returning a single IPv4 address to a TextBox. This works fine.
I have a need to return all active IPv4 addresses for computers like laptops which may have multiple NICs. This code does not seem to be able to return more than 1 IP address. When testing with two active connections this code randomly seems to pick one IP with no rhyme or reason.
Also, I would like to have this working for multiple IPv4 addresses but displayed in a ListBox rather than a TextBox.
This code also will not display my single IP output to a ListBox. I'm not sure why that isn't working.
Any help on both of these issues would be greatly appreciated. Thanks
Public Class Form1
Function ReturnLocalIP(ByVal Type As Net.Sockets.AddressFamily) As String
'Pass "Net.Sockets.AddressFamily.InterNetwork" for IPv4
'Pass "Net.Sockets.AddressFamily.InterNetworkV6" for IPv6'
Dim HostEntry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
For Each IP As Net.IPAddress In HostEntry.AddressList
If IP.AddressFamily = Type Then
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ReturnLocalIP(Net.Sockets.AddressFamily.InterNetwork)