这是我的代码,我可以获得 IP 地址和子网掩码,
Dim strHostName As String
Dim strIPAddress As String
Dim strMsg = ""
strHostName = System.Net.Dns.GetHostName()
strIPAddress = "" ' System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()
Dim iphe As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(strHostName)
For Each ipheal As System.Net.IPAddress In iphe.AddressList
If ipheal.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
strIPAddress = ipheal.ToString()
For Each adapter As Net.NetworkInformation.NetworkInterface In Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
For Each unicastIPAddressInformation As Net.NetworkInformation.UnicastIPAddressInformation In adapter.GetIPProperties().UnicastAddresses
If unicastIPAddressInformation.Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
If strIPAddress.Equals(unicastIPAddressInformation.Address.ToString ) Then
'Subnet Mask
Dim submark = unicastIPAddressInformation.IPv4Mask.ToString()
End If
End If
Next
Next
Exit For
End If
Next
我得到值 IP 地址=144.28.16.17 和子网掩码=255.255.240.0
如图所示,如何获得网络 ID?