-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsIPRanges.cls
executable file
·105 lines (80 loc) · 2.41 KB
/
clsIPRanges.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsIPRanges"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private mcolRanges As Collection
' ########################################################
' PROPERTIES
Public Property Get Count() As Long
Count = mcolRanges.Count
End Property
' ########################################################
' METHODS
Public Function NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = mcolRanges.[_NewEnum]
End Function
Public Function Item(vntKey As Variant) As clsIPRange
Set Item = mcolRanges.Item(vntKey)
End Function
Public Sub Remove(vntKey As Variant)
mcolRanges.Remove vntKey
End Sub
Public Sub Add(objNewIPRange As clsIPRange)
On Error GoTo ErrHandler
mcolRanges.Add objNewIPRange, objNewIPRange.UniqueID
Exit Sub
ErrHandler:
Remove objNewIPRange.UniqueID
mcolRanges.Add objNewIPRange, objNewIPRange.UniqueID
End Sub
Public Function AddressIsBlocked(sIP As String) As Boolean
Dim objRange As clsIPRange
On Error Resume Next
For Each objRange In mcolRanges
If objRange.Enabled Then
If objRange.IsInRange(sIP) Then
AddressIsBlocked = True
Exit For
End If
End If
Next objRange
End Function
Public Function BuildRegString() As String
Dim objRange As clsIPRange
Dim sText As String
For Each objRange In mcolRanges
sText = sText & IIf(Len(sText) > 0, Chr(0), "") & objRange.WriteToString
Next objRange
BuildRegString = sText
End Function
Public Sub BuildFromRegString(sData As String)
Dim objRange As clsIPRange
Dim asRanges() As String
Dim vntRange As Variant
Set mcolRanges = New Collection
asRanges = Split(sData, Chr(0))
For Each vntRange In asRanges
Set objRange = New clsIPRange
objRange.BuildFromString CStr(vntRange)
Add objRange
Next vntRange
Set objRange = Nothing
End Sub
Private Sub Class_Initialize()
Set mcolRanges = New Collection
End Sub
Private Sub Class_Terminate()
Set mcolRanges = Nothing
End Sub