'────────────────────────────────
'IP validation
Public Function Valid_IP(ByVal IP)
Dim i
Dim dot_count
Dim test_octet
Dim byte_check
IP = Trim(IP)
' Confirm IP length
If Len(IP) < &H08 Then
Valid_IP = False
'Show error message
Exit Function
End If
i = &H01
dot_count = &H00
For i = 1 To Len(IP)
If Mid(IP, i, &H01) = "." Then
' Increase the value of the point
' And set the text_octet value to empty
dot_count = dot_count + &H01
test_octet = ""
If i = Len(IP) Then
' If the point is at the end, the IP validation fails
Valid_IP = False
' Show error message
Exit Function
End If
Else
test_octet = test_octet & Mid(IP, i, &H01)
' Use error masking to check the correctness of data segment values
On Error Resume Next
' Convert the type
'If the conversion fails, you can confirm it by checking whether Err is true
byte_check = CByte(test_octet)
If (Err) Then
' Cases generate error
' The data of the segment value is not numerical
' or the data length of the taken segment value is greater than &HFF
' Then the type is not byte type
'The correctness of the IP address is false
Valid_IP = False
Exit Function
End If
End If
Next
' Through the verification in the previous step, you should now check whether there are 3 small dots
If dot_count <> &H03 Then
Valid_IP = False
Exit Function
End If
' Everything is OK, then the IP is the correct IP address
Valid_IP = True
End Function
'────────────────────────────────
' Convert a value to IP
Public Function CStringIP(ByVal anNewIP)
Dim lsResults
Dim lnTemp
Dim lnIndex
For lnIndex = &H03 To &H00 Step -&H01
lnTemp = Int(anNewIP / (&H100 ^ lnIndex))
lsResults = lsResults & lnTemp & "."
anNewIP = anNewIP - (lnTemp * (&H100 ^ lnIndex))
Next
lsResults = Left(lsResults, Len(lsResults) - &H01)
CStringIP = lsResults
End function
'────────────────────────────────
' Convert an IP to a numeric value
Public Function CLongIP(ByVal asNewIP)
Dim lnResults
Dim lnIndex
Dim lnIpAry
lnIpAry = Split(asNewIP, ".", &H04)
For lnIndex = &H00 To &H03
if Not lnIndex = &H03 Then
lnIpAry(lnIndex) = lnIpAry(lnIndex) * (&H100 ^ (&H03 - lnIndex))
End if
lnResults = lnResults + lnIpAry(lnIndex)
Next
CLongIP = lnResults
End function
'────────────────────────────────
' Get Client IP
Public Function GetClientIP()
dim uIpAddr
'This function reference/AspHouse document <take real customer IP>
uIpAddr = ("HTTP_X_FORWARDED_FOR")
If uIpAddr = "" Then uIpAddr = ("REMOTE_ADDR")
GetClientIP = uIpAddr
uIpAddr = ""
End function
'────────────────────────────────
' Read information about the IP location
Public function GetIpAddrInfo()
Dim tmpIpAddr
Dim IpAddrVal
Dim ic,charSpace
Dim tmpSQL
charSpace = ""
IpAddrVal = IpAddress
If Not Valid_IP(IpAddrVal) Then
GetIpAddrInfo =NULL
Exit Function
End If
'Clipping the IP string into an array for processing
tmpIpAddr = Split(IpAddrVal,".",-1,1)
For ic = &H00 To Ubound(tmpIpAddr)
'Complement operation, ensure that each interval meets 3 characters
Select Case Len(tmpIpAddr(ic))
Case &H01 :charSpace = "00"
Case &H02 :charSpace = "0"
Case Else :charSpace = ""
End Select
tmpIpAddr(ic) = charSpace & tmpIpAddr(ic)
Next
IpAddrVal = tmpIpAddr(&H00) & "." & tmpIpAddr(&H01) & "." & tmpIpAddr(&H02) & "." & tmpIpAddr(&H03)
'The following is the query. The IP address database is based on the IP database of null hunting. Thanks to Mr. Feng Zhihong for his contribution
'The library structure is as follows:
'CREATE TABLE [dbo].[wry] (
' [STARTIP] [nvarchar] (17) COLLATE Chinese_PRC_CI_AS NULL , --Start IP segment
' [ENDIP] [nvarchar] (17) COLLATE Chinese_PRC_CI_AS NULL , -- Terminate IP segment
' [COUNTRY] [nvarchar] (16) COLLATE Chinese_PRC_CI_AS NULL , -- Country or region
' [LOCAL] [nvarchar] (54) COLLATE Chinese_PRC_CI_AS NULL , --local address
' [THANK] [nvarchar] (23) COLLATE Chinese_PRC_CI_AS NULL --Thanks for correcting IP address user name
') ON [PRIMARY]
'After analyzing the data storage structure of the library, the accurate query method is summarized, and the following query process is detailed
tmpSQL = "select * from wry where (startIP<='" & IpAddrVal & "') and (ENDIP>='" & IpAddrVal & "') " & _
" and left(startIP," & Len(tmpIpAddr(&H00)) & ") = '" & tmpIpAddr(&H00) & "'" & _
" and left(endip," & Len(tmpIpAddr(&H00)) & ")='" & tmpIpAddr(&H00) & "'"
charSpace = GetDbIpInfo(tmpSQL)
If Len(charSpace)=&H00 Then
GetIpAddrInfo = NULL
Else
GetIpAddrInfo = charSpace
End If
charSpace = Null
tmpSQL = Null
end function
Previous page1234567891011121314151617181920Next pageRead the full text