<%@Language = VBScript CodePage = 936%>
<html>
<head>
<Title> Untitled Document </Title>
<meta http-equiv = content-type content = text/html; charset = gb2312>
</head>
<body>
<%
dim FinishGetip, Showip, Allip
'/////////////////////////////////////////////////////////////////////Gestingead ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Gons
'The program is not very streamlined, and then modify it later
'The database used in this program is- "Feng Zhihong"-written- "hunting"-the IP database and
The author of "Guohua Software Guohua Soft "-" Feng Guohua "— The" Global IP address allocation table.chm "written by.
'Thanks to the data provided by "Feng Zhihong" and "Feng Guohua"
'There are still many duplicate IP addresses in the database.
'My program is very clumsy. I hope everyone can give more opinions and communicate more, thank you!
'/////////////////////////////////////////////////////////////////////Gestingead ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Gons
'Solution:
'The obtained client IP is generally 202.11.25.1, and the IP format in the database is 202.011.025.001, which needs to be obtained
'Client IP converts to the same format as IP in the database
'Because the IP we currently use is divided into 4 sections, each section of 3 places, and the middle is separated by "."
'So my idea is to divide the client IP into 4 paragraphs from ".", That is, 202/11/25/1
'Then check each paragraph separately, if it is 3 digits, it will not change; if there are less than 3, it is 2, and 1 0 in front of this section, for 1, the same reason, then add 2 0
'After the formatting IP is obtained, the last section of the IP is removed, that is, the top 11 bits including "." Compared with the top 11 bits in the Startip field in the database, find the same value to find the same value
'Because it can be seen from the database, the first three paragraphs of Startip and Endip are the same, and the last paragraph is just the internal subnet address, which can be removed
'So as long as you take the top 11 of any field of Startip or ENDIP, compared with the top 11 of the client IP, you can find the right location
'/////////////////////////////////////////////////////////////////////Gestingead ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Gestman
Function Checkip_trueip ()
'Take the client real IP
getclientip = request.servervariables (http_x_Forwardeded_For) 'If the client uses the proxy server, use Request.servervariables (Remote_addr) method. X_FORWARDED_FOR) method
If getclientip = then
GetClientip = Equest.servervariables (Remote_addr) 'If the client does not use the agent, then Request.servervariables (http_x_Forwardededded_For) is empty value. Te_addr) method
end if
checkip_trueip = getClientip
end function
'/////////////////////////////////////////////////////////////////////Gestingead ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Ggig
Function GetaccessRecordSet (DB, SQL, MARK, Read) 'Obtain the RecordSet object
SET Conn = GetAccessconn (DB) 'Input parameter is the relative path of DB-database, SQL-SQL statement, Mark, Read is a database reading method, 1,1 is read and write
'Constr = Provider = Microsoft.jet.OLEDB.4.0; & Data Source = & Server.mAppath (DB)
'conn.open constr
Set GetAccessRecordSet = Server.CreateObject (Adodb.Recordset)
GetaccessRecordSet.open SQL, Conn, Mark, Read
end function
'/////////////////////////////////////////////////////////////////////Gestingead //////////////////////////
Function Getaccessconn (DB) '' Get the Connection object
Set GetAccessconn = Server.CreateObject (Adodb.Connection)
'Constr = Driver = {Microsoft Access Driver (*.mdb)}; DBQ = & Server.mAppath (allcon/#bbsall.mdb)
constr = provider = microsoft.jet.OLEDB.4.0; & Data Source = & Server.MAPPATH (DB)
getaccessconn.open constr
end function
'/////////////////////////////////////////////////////////////////////Gestingead /////////////////////////
dim getip
'Getip = (Trim (Request.servervariables (Remote_addr))') 'Get IP from the client
'Getip = (Trim (Request.queryString (Comes))') 'Enter IP test by myself
'Response.write (Getip & <br>)
'/////////////////////////////////////////////////////////////////////Gestingead ////////////////////////
Function Checkip_Locations (Checkstring) 'Back to the position function of the separated character in the IP
Checkip_Locations = Instr (Checkstring ,.) 'to give functions to the function
end function
'/////////////////////////////////////////////////////////////////////Gestingead //////////////////////
'The following functions are the division IP, and the IP remaining string of the IP on the right after each segmentation is obtained
Function Checkip_left (Checkstring)
Locations_Left = Checkip_Locations (Checkstring) 'to get the first place where the first appeared in the remaining string of the IP
iPlength_Left = Len (Checkstring) 'Get the length of the remaining string of the IP
Divide_locations_Left = iPlength_Left-Locations_Left 'to get the position of "." for the first time in the remaining string of the IP.
IPStr_Left = Right (Checkstring, Divide_locations_left) 'After obtaining this division, the remaining string of the IP remaining on the right of the "."
Checkip_left = iPStr_Left 'will give the string obtained above to the function
end function
'/////////////////////////////////////////////////////////////////////Gestingead //////////////////////
'The following functions are divided IP, and the IP string on the left side of the "." Symbol after each segmentation is obtained.
Function Checkip_right (Checkstring)
Locations_right = Checkip_Locations (Checkstring) 'Obtained in the IP "."
iPlength_right = Len (Checkstring) 'Get the IP string length
Divide_locations_right = iPlength_right-Locations_right 'to get the position of "." for the first time in the IP remaining string. How many bits are from right to left
ipstr11 = Trim (REFT (left (checkstring, local),.,.,) ')') ') The "." left string on the left will be removed. Symbols
'If the IP is divided into 4 paragraphs, each section is less than 3 digits, and 0
If Len (IPSTR11) = 2 then IPSTR11 = 0 & ipstr11
if len (ipstr11) = 3 then ipstr11 = ipstr11
If Len (IPSTR11) = 1 TheN IPSTR11 = 00 & ipstr11
Checkip_right = iPStr11 'Get the string before the "." Symbol, that is, the IP segmentation obtained after this segmentation is one of the four sections
END FUNCTI
The largest cool station demonstration center in China!