首页 > 文章列表 > ASP中如何使用Instr判断多个IP地址是否存在?

ASP中如何使用Instr判断多个IP地址是否存在?

346 2025-02-16

ASP中如何使用Instr判断多个IP地址是否存在?

asp中用instr判断多个ip地址

在asp中,可以通过使用instr函数来判断字符串中是否包含指定子字符串。但是,如果需要判断字符串中是否包含多个子字符串,则需要采用其他方法。

一种方法是使用循环遍历,对每个子字符串执行instr判断:

<%
Dim aa, ipList, ip, found
aa = Request.ServerVariables("REMOTE_ADDR")

ipList = Array("99.88", "110.52", "43.80.235", "11.9.67.180")
found = False

For Each ip In ipList
    If InStr(aa, ip) > 0 Then
        found = True
        Exit For
    End If
Next

If found Then
    Response.Write "ok"
    Response.End
End If
%>

这种方法更具灵活性,可以轻松添加或删除需要判断的子字符串。

来源:1733119528