支持多个通配符,任意通配符位置,可屏蔽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
5
If IsForbidIP(BadIPGroup) = True Then
6
Response.Write(GetIP &"IP地址禁止访问")
7
Response.End()
8
End If
9
10
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
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

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

另,网上看到的另一个用加减乘除来判断的,有点取巧,单很不灵活,且代码似乎还有问题。仅供参考。



































