Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
TextBox1.Text = GetIpAddressLinq.ToString()
'TextBox1.Text = GetIpAddress.ToString()
End Sub
'Use linq
Public Function GetIpAddressLinq() As Net.IPAddress
Dim host = Net.Dns.GetHostEntry(Net.Dns.GetHostName())
Return host.AddressList.FirstOrDefault(Function(x As Net.IPAddress) _
x.AddressFamily = Net.Sockets.AddressFamily.InterNetwork)
End Function
'Use for next loop
Public Function GetIpAddress() As Net.IPAddress
Dim host = Net.Dns.GetHostEntry(Net.Dns.GetHostName())
For Each address In host.AddressList
If address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
Return address
End If
Next
Return Nothing
End Function