ASP writes a complete version of the copy of the IP location
Fixed the query method, the method of queries and the consistency of pursuit; just pursuing the IP automatically.
There is also a function of writing errors and has been amended;
Includes verification functions that add an IP address correctness. (Just judging from format)
<%
Server.scripttimeout = & HE10 '& H3C
Response.buffer = ("s.f." = "sf.")
DIM IPSEARCH
'Establish an object
Set ipsearch = new CLSIPSEARCH
'This sentence establishes the connection to the IP address library of SQL Server, you can use the default connection, but to ensure that Wry.mdb
IPsearch.connectionstring = "driver = {SQL Server}; server = hostname: uid = sa; pwd =; dataBase = IP"
'Set the IP you want to query, you can use the default value, set 127.0.0.1
IPsearch.ipaddress = & h7f & "." & "& H00 &". "& H01
If Request.QueryString ("IP") <> ""
If ipsearch.valid_ip (Request.QueryString ("IP")) THEN
IPsearch.ipaddress = trim (Request.QueryString ("IP"))
END IF
END IF
'Get the location of IP, there are three feedback values, divided by comma
'Format is: the country or region, local Internet area, user name to provide correct IP address information
Response.write ("location:" & ipsearch.getipaddrinfo () & "
")
'Remove the IP address
Response.write ("IP:" & IPSearch.ipaddress & "
")
'Convert IP addresses to values
Response.write ("IP conversion is numerical:" & ipsearch.clongip (ipsearch.ipaddress) & "
")
'Restore the IP address to the value after the IP string
Response.write ("Numeric Restore is IP:" & IPSearch.cstringIP (IPSearch.Clongip (IPSearch.ipaddress) & "
")
Response.write ("
'This is the test code
'DIM A, B, C, D
'for a = 0 to 255
'for b = 0 to 255 Step 20
'for c = 0 to 255 Step 20
'for d = 0 to 255 step 20
'Ipsearch.ipaddress = a & "." & B & "." & C & ". & D' response.write (" location: "& ipsearch.getipaddrinfo () &"
")
'Response.Write ("IP:" & ipsearch.ipaddress & "
")
'Response.write ("IP conversion is numerical:" & ipsearch.clongip (ipsearch.ipaddress) & "
")
'Response.write ("numerical reduction is IP:" & ipsearch.cstringIP (ipsearch.clongip (ipsearch.ipaddress) & "
")
'Response.write ("
'Next
'Next
'Next
'Next
%>
<%
Class CLSIPSEARCH
'######################################################## #################
'Statement: The data used by this program is "Hui Zhihong" "Hui Zhihong" "Hui Zhihong", which is "pursued" on the network.
'Mr.' carefully collected finishing.
'"Pursuing" Database Conversion Method:
'Modify the Wry.dll file suffix name to wry.dbf
'method one:
'Start Access data, select Open the database, select the open file type "DBASE 5 (* .dbf)"
'Open Wry.dbf file, select "Conversion Database" in Database Utilities under Tools menu
'Select "Convert to Access 97 Format (version optional)" feature, save the file into the MDB format.
'Method Two:
'Use the "Import and Export Data" wizard provided by SQL Server.
'Brief Description: Set the DSN to Wry.dbf in the ODBC Control Panel.
'Use the Import and Export Data Wizard, select its correct driver and the library to import.
'Or directly import the MDB file that is generated by the method.
'Method three:
'Use Access to open the Wry.dbf file and will automatically pass the original library data through the MDB library.
'
'No other database platform is installed, other methods are owed.
'########################################################################################################################################################################################################################################################################################################## ###########
'# I 地 Search Class
'# Connectionstring is a database connection declaration, the default declaration of Wry.mdb in the same class directory
'# Ipaddress Please set to the search for the IP address, default to take the current visitor IP
'# Class establishment method
'# DIM objval' declares a variable
'# Set objval = new clsipsearch' build class object
'# Response.write (objval.ipaddress)' Displays the current visitor IP
'# Ip search class method list:
'# .Valid_ip' IP address correctness test '# parameter: IP' IP value or string
'# .Clongip' converts IP addresses to long integer values
'# Parameters: Asnewip' To convert the IP address string
'# .Cstringip' converts long integer values to IP
'# Parameters: Annewip' To restore the value of IP address
'# .Getclientip' takes the visitors' IP
'# .Getipaddrinfo' gets the IP where IPAddress property is set.
'# Property list (automatic initialization):
'# Connectionstring' ADO Access Database Connection Description
'# Ipaddress' To operate the IP address
'# Internal error handling:
'# Lack, not done, please supplement it.
'######################################################## #################
Public Connectionstring
Public ipaddress
Private dbconn 'connection object, modular grade statement
'- ─────────────────────────
'Initialization
Private sub coplass_initialize ()
'The MDB library file generated by "data conversion-method one" is created.
Connectionstring = "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("Wry.mdb")
Ipaddress = getClientip ()
Set dbconn = OpenConnection ()
End Sub
'- ─────────────────────────
'Class logout
Private sub coplass_terminate ()
Connectionstring = NULL
Ipaddress = null
Dbconn.close
Set dbconn = Nothing
End Sub
'- ─────────────────────────
'Creating a connection
Private function openconnection ()
DIM TMPCONNNNNNN
SET TMPCONN = Server.createObject ("AdoDb.Connection")
TMPCONN.OPEN Connectionstring
Set openConnection = TMPCONN
SET TMPCONN = Nothing
END FUNCTION
'- ─────────────────────────
'Execute a SQL command and return a dataset object
Private function SQLEXECUTE (STRSQL)
DIM RS
SET RS = dbconn.execute (strsql)
Set Sqlexecute = RS
SET RS = Nothing
END FUNCTION
'- ─────────────────────────
'IP test
Public Function Valid_ip (BYVAL IP)
DIM I
Dim dot_count
DIM TEST_OCTETDIM BYTE_CHECK
IP = TRIM (IP)
'Confirm the IP length
IF LEN (IP) <& H08 THEN
VALID_IP = FALSE
'Display error prompt
EXIT FUNCTION
END IF
i = & h01
Dot_count = & H00
For i = 1 to Len (IP)
IF MID (IP, I, & H01) = "." "
'Increase the count value
'And set the Text_OCTET value empty
Dot_count = dot_count & h01
Test_OCTET = ""
IF i = len (ip) THEN
'If the point is ending, the IP papers failed.
VALID_IP = FALSE
'Display error prompt
EXIT FUNCTION
END IF
Else
Test_OCTET = TEST_OCTET & MID (IP, I, & H01)
'Use error shield to check the correctness of the data segment value
ON Error ResMe next
'Mandatory type conversion
'If the conversion fails, you can check if Err is true.
BYTE_CHECK = CBYTE (Test_OCTET)
IF (ERR) THEN
'Forced type conversion errors
'The data of the value obtained is not valued.
'Or the data length of the segment value is greater than & hff
', Type is not a BYTE type
The correctness of the 'IP address is false
VALID_IP = FALSE
EXIT FUNCTION
END IF
END IF
NEXT
'Validation by the previous step, should now check if there is 3
IF dot_count <> & h03 THEN
VALID_IP = FALSE
EXIT FUNCTION
END IF
'Everything is normal, then the IP is the correct IP address.
VALID_IP = TRUE
END FUNCTION
'- ─────────────────────────
'Convert a value for IP
Public Function CSTRING (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 values
Public Function Clongip (ByVal Asnewip)
Dim lnResults
Dim lnindex
DIM Lnipary
Lnipary = split (asnewip, ".", & h04)
For lnindex = & h00 to & h03
IF not lnindex = & h03 kilnipary (lnindex) = lnipary (lnindex) * (& H100 ^ (& H03 - lnIndex))
END IF
LnResults = lnResults lnipary (lnIndex)
NEXT
Clongip = lnResults
END FUNCTION
'- ─────────────────────────
'Take a Client IP
Public function getClientip ()
DIM UIPADDR
'This function refers to Webcn.Net/asphouse document
UIPADDR = Request.ServerVariables ("http_x_forwarded_for")
IF uipaddr = "" THEN UIPADDR = Request.ServerVariables ("remote_addr")
GetClientip = UIPADDR
UIPADDR = ""
END FUNCTION
'- ─────────────────────────
'Read the information of 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
'Split the IP string to the metrics
Tmpipaddr = split (ipaddrval, ".", - 1, 1)
For IC = & H00 To Ubound (TmpiPaddr)
'Adding place to ensure that 3 characters per space
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 = tmpaddr (& H00) & "." & Tmpaddr (& h01) & "& tmpaddr (& h02) &". "& Tmpaddr (& h03)
'The following is the query, IP address library based on "chasing" IP database, thanks to Mr. Feng Zhihong
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, - Termination 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 to the correction IP address user name
') On [primary]
'The data storage structure of the analysis library, summarizes the accurate query method, and specifically looks at the following query process.
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
'- ─────────────────────────
'Returns the string of data queries
Private function getDBipinfo (Byval SQL)
DIM OpenIPSearchrs
Dim Result
Set openipsearchrs = SQLEXECUTE (SQL)
IF not openipsearchrs.eof kil
Result = Nulltospace (OpenIPSearchrs ("Country") & "& NullTospace (OpenIPSearchrs (" Local ") &", "& Nulltospace (OpenIPSearchrs (" Thank ")
Else
Result = NULL
END IF
OpenIPSEARCHRS.CLOSE
Set openipsearchrs = Nothing
GetDBipinfo = Result
END FUNCTION
'- ─────────────────────────
'Convert data library empty record into empty characters
Private function Nulltospace (Byval RSSTR)
IF Isnull (Rsstr) THEN
Nulltospace = ""
Else
Nulltospace = Trim (RSSTR)
END IF
END FUNCTION
END CLASS
%>