支持多个通配符,任意通配符位置,可屏蔽IP段和具体IP地址
1
'
By zkxp 2/15/2006 http://zkxp.cnblogs.com
2
'
受屏蔽IP地址(段)集合,星号为通配符,通常保存于配置文件中。
3
Const
BadIPGroup
=
"
192.168.1.*|202.68.*.*|*.12.55.34|185.*.96.24|127.*.0.1|192.168.0.1
"
4![None.gif](/Images/OutliningIndicators/None.gif)
5
If
IsForbidIP(BadIPGroup)
=
True
Then
6
Response.Write(GetIP
&
"
IP地址禁止访问
"
)
7
Response.End()
8
End
If
9![None.gif](/Images/OutliningIndicators/None.gif)
10![None.gif](/Images/OutliningIndicators/None.gif)
11
'
****************************************************************
12
'
参数vBadIP:要屏蔽的IP段,IP地址集合,用|符号分隔多个IP地址(段)
13
'
返回Bool:True用户IP在被屏蔽范围,False 反之
14
'
****************************************************************
15
Function
IsForbidIP(vBadIP)
16
Dim
counter, arrIPPart, arrBadIP, arrBadIPPart, i, j
17
18
arrBadIP
=
Split
(vBadIP,
"
|
"
)
19
arrIPPart
=
Split
(GetIP(),
"
.
"
)
20
21
For
i
=
0
To
UBound
(arrBadIP)
22
counter
=
0
23
arrBadIPPart
=
Split
(arrBadIP(i),
"
.
"
)
24
For
j
=
0
To
UBound
(arrIPPart)
25
If
(arrBadIPPart(j))
=
"
*
"
or
Cstr
(arrIPPart(j))
=
Cstr
(arrBadIPPart(j))
Then
26
counter
=
counter
+
1
27
End
If
28
Next
29
If
counter
=
4
Then
30
IsForbidIP
=
True
31
Exit
Function
32
End
If
33
Next
34
IsForbidIP
=
False
35
End Function
36![None.gif](/Images/OutliningIndicators/None.gif)
37
'
***************
38
'
返回客户IP地址
39
'
***************
40
Function
GetIP()
41
Dim
IP
42
IP
=
Request.ServerVariables(
"
HTTP_X_FORWARDED_FOR
"
)
43
If
IP
=
""
Then
IP
=
Request.ServerVariables(
"
REMOTE_ADDR
"
)
44
GetIP
=
IP
45
End Function
![None.gif](/Images/OutliningIndicators/None.gif)
2
![None.gif](/Images/OutliningIndicators/None.gif)
3
![None.gif](/Images/OutliningIndicators/None.gif)
4
![None.gif](/Images/OutliningIndicators/None.gif)
5
![None.gif](/Images/OutliningIndicators/None.gif)
6
![None.gif](/Images/OutliningIndicators/None.gif)
7
![None.gif](/Images/OutliningIndicators/None.gif)
8
![None.gif](/Images/OutliningIndicators/None.gif)
9
![None.gif](/Images/OutliningIndicators/None.gif)
10
![None.gif](/Images/OutliningIndicators/None.gif)
11
![None.gif](/Images/OutliningIndicators/None.gif)
12
![None.gif](/Images/OutliningIndicators/None.gif)
13
![None.gif](/Images/OutliningIndicators/None.gif)
14
![None.gif](/Images/OutliningIndicators/None.gif)
15
![None.gif](/Images/OutliningIndicators/None.gif)
16
![None.gif](/Images/OutliningIndicators/None.gif)
17
![None.gif](/Images/OutliningIndicators/None.gif)
18
![None.gif](/Images/OutliningIndicators/None.gif)
19
![None.gif](/Images/OutliningIndicators/None.gif)
20
![None.gif](/Images/OutliningIndicators/None.gif)
21
![None.gif](/Images/OutliningIndicators/None.gif)
22
![None.gif](/Images/OutliningIndicators/None.gif)
23
![None.gif](/Images/OutliningIndicators/None.gif)
24
![None.gif](/Images/OutliningIndicators/None.gif)
25
![None.gif](/Images/OutliningIndicators/None.gif)
26
![None.gif](/Images/OutliningIndicators/None.gif)
27
![None.gif](/Images/OutliningIndicators/None.gif)
28
![None.gif](/Images/OutliningIndicators/None.gif)
29
![None.gif](/Images/OutliningIndicators/None.gif)
30
![None.gif](/Images/OutliningIndicators/None.gif)
31
![None.gif](/Images/OutliningIndicators/None.gif)
32
![None.gif](/Images/OutliningIndicators/None.gif)
33
![None.gif](/Images/OutliningIndicators/None.gif)
34
![None.gif](/Images/OutliningIndicators/None.gif)
35
![None.gif](/Images/OutliningIndicators/None.gif)
36
![None.gif](/Images/OutliningIndicators/None.gif)
37
![None.gif](/Images/OutliningIndicators/None.gif)
38
![None.gif](/Images/OutliningIndicators/None.gif)
39
![None.gif](/Images/OutliningIndicators/None.gif)
40
![None.gif](/Images/OutliningIndicators/None.gif)
41
![None.gif](/Images/OutliningIndicators/None.gif)
42
![None.gif](/Images/OutliningIndicators/None.gif)
43
![None.gif](/Images/OutliningIndicators/None.gif)
44
![None.gif](/Images/OutliningIndicators/None.gif)
45
![None.gif](/Images/OutliningIndicators/None.gif)
另,网上看到的另一个用加减乘除来判断的,有点取巧,单很不灵活,且代码似乎还有问题。仅供参考。
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)
![None.gif](/Images/OutliningIndicators/None.gif)