我正在尝试删除IP地址的最后一个八位字节,我不知道从哪里开始。
我目前能够获取主机IP,但需要更改它。
当前代码:
Private Function GetIPv4Address() As String
GetIPv4Address = String.Empty
Dim strHostName As String = System.Net.Dns.GetHostName()
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
GetIPv4Address = ipheal.ToString()
End If
Next
IP = GetIPv4Address
End Function
以上输出xx.xx.xx.xxx
目标是让它输出xx.xx.xx。
答案 0 :(得分:2)
替换:
IP = GetIPv4Address
有了这个:
IP = Left(GetIPv4Address, GetIPv4Address.LastIndexOf("."))
查看有关Left和LastIndexOf方法的更多信息。