万卷书   首页 > 电脑书籍 > Asp > ASP编写完整的IP所在地搜索类
 

   '##################################################################


   Public ConnectionString
   Public IpAddress
   Private DBConn '连接对象,模块级声明
   '────────────────────────────────
   ' 类初始化
   Private Sub Class_initialize()
   ' 这里建立的是通过“数据转换--方法一”生成的mdb 库文件
   ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("wry.mdb")
   IpAddress = GetClientIP()
   Set DBConn = OpenConnection()
   End Sub
   '────────────────────────────────
   ' 类注销
   Private Sub Class_Terminate()
   ConnectionString = Null
   IpAddress = Null
   DBConn.Close
   Set DBConn = Nothing
   End Sub
   '────────────────────────────────
   ' 建立一个连接
   Private Function OpenConnection()
   Dim tmpConn
   Set tmpConn=Server.CreateObject("ADODB.Connection")
   tmpConn.Open ConnectionString
   Set OpenConnection=tmpConn
   Set tmpConn=nothing
   End Function
   '────────────────────────────────
   ' 执行一个SQL命令,并返回一个数据集对象
&bsp;   Private Function SQLExeCute(strSql)
   Dim Rs
   Set Rs=DBConn.ExeCute(strSQL)
   Set SQLExeCute = Rs
   Set Rs=nothing
   End Function
   '────────────────────────────────
   'IP 效验
   Public Function Valid_IP(ByVal IP)
   Dim i
   Dim dot_count
   Dim test_octet
   Dim byte_check
   IP = Trim(IP)
   ' 确认IP长度
   If Len(IP) < &H08 Then
   Valid_IP = False
   '显示错误提示
   Exit Function
   End If

   i = &H01
   dot_count = &H00
   For i = 1 To Len(IP)
   If Mid(IP, i, &H01) = "." Then
   ' 增加点的记数值
   ' 并且设置text_octet 值为空
   dot_count = dot_count + &H01
   test_octet = ""
   If i = Len(IP) Then
   ' 如果点在结尾则IP效验失败
   Valid_IP = False
   ' 显示错误提示
   Exit Function
   End If
   Else
   test_octet = test_octet & Mid(IP, i, &H01)
   ' 使用错误屏蔽来检查数据段值的正确性
   On Error Resume Next
   ' 进行强制类型转换
   ' 如果转换失败就可通过检查Err是否为真来确认
   byte_check = CByte(test_octet)
   If (Err) Then
   ' 强制类型转换产生错误
   ' 所取段值的数据不为数值
   ' 或所取段值的数据长度大于&HFF
   ' 则类型不为byte类型
   ' IP 地址的正确性为假
   Valid_IP = False
   Exit Function
   End If
   End If
   Next


上一页 下一页