[VB]本機IP查詢

執行Class以後就可以將ip帶入變數

Imports System.Net.Dns
 
Public Function GetIPaddress() As String

    Try

        Dim ipEntry As System.Net.IPHostEntry = GetHostByName(Environment.MachineName)
        Dim IpAddr As System.Net.IPAddress() = ipEntry.AddressList
 
        GetIPaddress = IpAddr(0).ToString

    Catch ex As Exception

        GetIPaddress = "無法取得IP"

    End Try

End Function