ASP to write a complete IP location search class (fixed)

Source: Internet
Author: User
Tags format error handling integer numeric list of attributes numeric value query access database
Fixed the Query method, the query method and the pursuit of the same; just chasing will automatically correct IP.
There is also a function of the writing error, has also been corrected;
Includes a validation function that adds the correctness of an IP address. (Just judging from the format)
<%
' Author: She (s.f.)
' QQ No.: 410000
Server.ScriptTimeout = &he10 ' &h3c
Response.Buffer = ("s.f." = "s.f.")
Dim Ipsearch
' Set up objects
Set Ipsearch = New Clsipsearch
' This sentence establishes a connection to the IP address library of SQL Server that can use the default connection, but is guaranteed to exist Wry.mdb
ipsearch.connectionstring = "Driver={sql Server}"; Server=hostname:uid=sa; pwd=;D Atabase=ip "
' Set the IP that you want to query for, the default value, set here is 127.0.0.1
ipsearch.ipaddress = &h7f & ". & &h00 &". "& &h00 &". "& &h01
If request.querystring ("IP") <> "Then
If ipsearch.valid_ip (Request.QueryString ("IP")) Then
ipsearch.ipaddress = Trim (Request.QueryString ("IP"))
End If
End If
' Gets the IP location, the feedback value is three, separated by commas
' The format is: the country or region, the local area of the Internet, provide the correct IP address information of the user name
Response.Write ("Location:" & Ipsearch.getipaddrinfo () & "<br>")
' Remove IP Address
Response.Write ("IP:" & ipsearch.ipaddress & "<br>")
' Converts an IP address to a numeric value
Response.Write ("IP conversion to numeric value:" & Ipsearch.clongip (ipsearch.ipaddress) & "<br>")
' Convert IP address to numeric value and revert to IP string
Response.Write ("Numeric revert to IP:" & Ipsearch.cstringip (IPSEARCH.CLONGIP (ipsearch.ipaddress)) & "<br>")
Response.Write ("
' Here is the test code
' Dim a,b,c,d
' For a = 0 to 255
' For b= 0-255 Step 20
' For c=0 to 255 step 20
' For d = 0-255 Step 20
' ipsearch.ipaddress = A & '. "& B &". "& C &". "& D
' Response.Write ("Location:" & Ipsearch.getipaddrinfo () & "<br>")
' Response.Write ("IP:" & ipsearch.ipaddress & "<br>")
' Response.Write (IP conversion to numeric value: "& Ipsearch.clongip (ipsearch.ipaddress) &" <br> ")
' Response.Write ("Numeric revert to IP:" & Ipsearch.cstringip (IPSEARCH.CLONGIP (ipsearch.ipaddress)) & "<br>")
' Response.Write ("' Next
' Next
' Next
' Next
%>
<%
Class Clsipsearch
'##################################################################
' Disclaimer: This procedure uses the data for the network's famous IP tool software "Chase" author "Feng Zhihong"
Mr. ' meticulously collected and collated.
The conversion method of the "Hunt" database:
' Modify wry.dll file suffix name to wry.dbf
' Method One:
' Start Access data, select Open Database, and choose Open File Type ' DBASE 5 (*.dbf) '
' Open the Wry.dbf file and select the transform database in the Database utility under the Tools menu
' Select the Convert to Access 97 format (version optional) feature to save the file as an MDB format.
' Method Two:
' Use the Import and Export Data Wizard provided by SQL Server.
' Method Brief Description: Set the DSN pointing to wry.dbf in the ODBC Control Panel.
' Using the Import and Export Data Wizard, select the correct driver and the library you want to import.
' or import the MDB file generated by method one directly into the library.
' Method Three:
' Using access to open the Wry.dbf file automatically references the original library data through the MDB library.
'
' No other database platforms are installed, other methods are not considered.
' ###################### class Description ####################################
' # IP Location search class
' # ConnectionString for the database connection declaration, the default declaration of the sibling directory Wry.mdb
' # ipaddress Please set the IP address for the search, by default take the current visitor IP
' # class Building method
' # Dim Objval ' declares a variable
' # Set objval = New Clsipsearch ' Create class object
' # Response.Write (objval.ipaddress) ' Displays current visitor IP
' # IP Search class method list:
'# . Valid_ip ' IP address correctness
' # parameter: IP ' IP value or string
'#  . Clongip ' converts an IP address to a value of a long integer
' # parameter: Asnewip ' the IP address string to convert
'#  . Cstringip ' Converts the value of a long integer to IP
' # parameter: Annewip ' value to revert to IP address
'#  . Getclientip ' Fetch the IP of the visitor
'#  . Getipaddrinfo ' Gets the IP location where the IPAddress attribute is set
' # List of attributes (automatically initialized):
' # ConnEctionString ' ADo Access database connection description
' # ipaddress ' IP address to operate
' # INTERNAL error handling:
' # Missing, not done, please add yourself.
'##################################################################

Public ConnectionString
Public IPAddress
Private dbconn ' Connection object, module-level declaration
' ────────────────────────────────
' Class initialization
Private Sub Class_Initialize ()
' Here is the MDB library file generated through data conversion--method one.
connectionstring= "Driver={microsoft Access DRIVER (*.mdb)};D bq=" & Server.MapPath ("Wry.mdb")
IPAddress = Getclientip ()



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.