'''''' 取得本機IPAddress ''' '''IPAddress Public Shared Function GetIPaddress() As String Dim myHost As String = System.Net.Dns.GetHostName Dim myIPs As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(myHost) For Each ipAddress As System.Net.IPAddress In myIPs.AddressList Return ipAddress.ToString() Next Return String.Empty End Function
二,取得本機所有網卡IPAddress
Private Function GetIPaddress() As List(Of String) Dim IpAddressList As New List(Of String) Try '取得本機上ipv4及非Loopback的IP Address For Each nic As System.Net.NetworkInformation.NetworkInterface In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() For Each ipInfo As System.Net.NetworkInformation.IPAddressInformation In nic.GetIPProperties().UnicastAddresses If System.Net.IPAddress.IsLoopback(ipInfo.Address) = False _ AndAlso ipInfo.Address.AddressFamily <> Net.Sockets.AddressFamily.InterNetworkV6 Then '取得IP Address IpAddressList.Add(ipInfo.Address.ToString()) End If Next Next Return IpAddressList Finally IpAddressList = Nothing End Try End Function
沒有留言:
張貼留言