Allow CIDR block syntax and text wildcards in search boxes
Searching large SNMP discovery score results would be easier.
This would be easier to do if the IP addresses were converted to a numeric value that was also available for sort/selection - this should be an auto-calculated value for any record that has an IP address.
This would also allow true sorting by IP address, not a text sort.
Here's sample functions:
'----------------------------------------------
' IpStrToBin for IP V4
'----------------------------------------------
' Converts a text IP address to binary
' example:
' IpStrToBin("1.2.3.4") returns 16909060
Function IpStrToBin(ByVal ip As String) As Double
Dim pos As Integer
ip = ip + "."
IpStrToBin = 0
While IP <> ""
pos = InStr(IP, ".")
IpStrToBin = IpStrToBin * 256 + Val(Left(ip, pos - 1))
ip = Mid(ip, pos + 1)
Wend
End Function
'----------------------------------------------
' Ipv6ToBin
'----------------------------------------------
' returns a string representing the binary value of IPv6 address
' the result has a fixed lenght of 128 characters
Function Ipv6ToBin(ByVal ip As String) As Variant
Dim result As String
ip2 = Replace(Ipv6Expand(IP), ":", "")
For i = 1 To Len(ip2)
b = "0000"
j = 0
v = Val("&H" & Mid$(ip2, i, 1))
While v > 0
Mid$(b, 4 - j, 1) = v Mod 2
v = v \ 2
j = j + 1
Wend
result = result & b
Next
Ipv6ToBin = result
End Function
Please sign in to leave a comment.
Comments
0 comments