Reputation: 483
I am trying to remove the last octet of an IP address and I have no idea where to start.
I am currently able to get the host computers IP, but need to alter it.
Current Code:
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
The above outputs xx.xx.xx.xxx
The goal is to have it output xx.xx.xx.
Upvotes: 0
Views: 1710
Reputation: 4036
Replace:
IP = GetIPv4Address
With this:
IP = Left(GetIPv4Address, GetIPv4Address.LastIndexOf("."))
See more info on Left and LastIndexOf methods.
Upvotes: 2