< %@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
'//////////////////////////////////////////////////// ////////
'The program is not very streamlined yet and will be modified later.
'The database used by this program is - "Feng Zhihong" - written by - "Punt" - the IP database included in the software and
'The "Global IP Address Allocation Table.chm" written by the author of "Guohua Soft" - "Feng Guohua" - is combined into one
'Thanks to "Feng Zhihong" and "Feng Guohua" for providing data
'There are still many duplicate IP addresses in the database. I hope someone can delete them and reduce the size of the database.
'My program is still very clumsy. I hope everyone can give me more opinions and communicate more. Thank you!
'//////////////////////////////////////////////////// //////////
'Solution: www.downcodes.com
'The obtained client IP is usually 202.11.25.1, and the IP format in the database is 202.011.025.001, which requires the obtained
'Convert the client IP to the same format as the IP in the database
'Because the IP we currently use is divided into 4 segments, each segment has 3 digits, separated by "."
'So my idea is to divide the client IP into 4 segments with the "." symbol, that is, 202/11/25/1
'Then check each paragraph separately. If it is 3 digits, it will remain unchanged; if it is less than 3 digits, it will be 2 digits. Add 1 0 in front of the paragraph and it will be 1. Similarly, add 2 0s.
'After getting the formatted IP, remove the last segment of the IP, that is, take the first 11 digits including ".", compare it with the first 11 digits of the startip field in the database, and find the same value
'Because it can be seen from the database that the first three segments of startip and endip are the same, and the last segment is just the internal subnet address and can be removed.
'So just take the first 11 digits of any field of startip or endip and compare it with the first 11 digits of the client IP to find the correct location.
'//////////////////////////////////////////////////// ///////////////
function checkip_trueip()
'Get the real IP of the client
getclientip = Request.ServerVariables("HTTP_X_FORWARDED_FOR") 'If the client uses a proxy server, the Request.ServerVariables("REMOTE_ADDR") method can only get a null value, then the ServerVariables("HTTP_X_FORWARDED_FOR") method should be used
If getclientip = "" Then
getclientip = Request.ServerVariables("REMOTE_ADDR")'If the client does not use a proxy, Request.ServerVariables("HTTP_X_FORWARDED_FOR") will get a null value, and the Request.ServerVariables("REMOTE_ADDR") method should be used
end if
checkip_trueip = getclientip
end function
'//////////////////////////////////////////////////// ////////
function getaccessrecordset(db,sql,mark,read)'Get Recordset object
set conn=getaccessconn(db)'The input parameters are the relative path of db-database, sql-SQL statement, mark, read are database reading methods, 1,1 are read-only, 1,3 are read-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
'//////////////////////////////////////////////////// ///////////
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
'//////////////////////////////////////////////////// ///////////
dim getip
'getip=(trim(request.ServerVariables("REMOTE_ADDR")))'Get IP from client
'getip=(trim(request.QueryString("comes"))) 'Enter the IP yourself to test
'response.Write(getip&"<br>")
'//////////////////////////////////////////////////// ///////////
function checkip_locations(checkstring) 'Returns the location function of the delimiting character in IP
checkip_locations=Instr(checkstring,".") 'Assign the value of the location to the function
end function
'//////////////////////////////////////////////////// ///////////
'The following function is to split IP and obtain the remaining string of IP on the right side of the "." symbol after each split
function checkip_left(checkstring)
locations_left=checkip_locations(checkstring) 'Get the location where "." first appears in the remaining string of IP
iplength_left=Len(checkstring) 'Get the length of the remaining string of the IP
divide_locations_left=iplength_left-locations_left 'Get the position where "." first appears in the remaining string of IP, how many digits are there from right to left
ipstr_left=Right(checkstring,divide_locations_left) 'Get the remaining string of IP on the right side of the "." symbol after this split
checkip_left=ipstr_left 'Assign the string obtained above to the function
end function
'//////////////////////////////////////////////////// //////////
'The following function is to split the IP and obtain the IP string to the left of the "." symbol after each split, that is, the IP is divided into four segments, and the string function of each segment
is checkip_right(checkstring)
locations_right=checkip_locations(checkstring) 'Get the location where "." first appears in the IP
iplength_right=Len(checkstring) 'Get the IP string length
divide_locations_right=iplength_right-locations_right 'Get the position where "." first appears in the remaining string of IP, how many digits are there from right to left
ipstr11=Trim(Replace(Left(checkstring,locations_right),".","")) 'Remove the "." symbol from the string to the left of the obtained "."
'If the IP is divided into 4 segments and each segment is less than 3 digits, add 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, one of the four segments after the IP is divided into four segments.
end function
'////////////////////////////////////////////////// //////////
'Check whether the IP is an internal network IP
'The judgment I wrote is based on: 127.0.0.0-127.XXX.XXX.255 and 192.0.0.0-192.XXX.XXX.255. If it is these two, it is the internal network IP, otherwise it is the external network.
'I don't know what the basis is for judging internal IP, so I need experts to give me some advice and make corrections. Contact me.
function checkiplocal(checkstring)
dim re1
set re1=new RegExp 'Get regular expression object
The expression in 're1.pattern is that the IP of the internal network should start with 127 or 192, and the middle should be any 1-3 numbers from 0-9 plus "." to form a paragraph
re1.pattern="^(127.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})|(192. [0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})$"
re1.global=false
re1.Ignorecase=false
checkiplocal=re1.test(checkstring)
set re1=nothing
end function
'//////////////////////////////////////////////////// ///////////////////////
function checkip_remote(checkstring)
dim iplength 'The length of the IP string
dim locations '"."The location where the character appears
iplength=Len(checksting)
locations=Instr(checkstring,".") 'Retrieve the position where the "." symbol first appears in the IP string from left to right
'Split the IP into 4 segments with "." characters
locations2=iplength-locations
ipstring1=Left(checkstring,locations)
ipstring2=Right(checkstring,locations2)
end function
'//////////////////////////////////////////////////// ////////
'//////////////////////////////////////////////////// ////////
ipinfo_local="Your IP is an intranet IP!"
ipinfo_remote="External network IP!"
getip=checkip_trueip()
currentip=checkiplocal(getip) 'Call the checkiplocal() function to check the obtained IP to determine whether it is an internal network address or an external network address
'if currentip=true then' test code
'response.Write(ipinfo_local)
if currentip=true then 'is false
response.Write(ipinfo_local)' indicates the internal network IP
else
'Convert
'The following is a loop extraction and bit-filling with 0 to divide the IP into 4 segments
locations=checkip_locations(getip)'Get the location where "." first appears in the IP before the first split
iplength=Len(getip) 'Get the length of the client IP
divide_locations=iplength-locations 'Get the location of the client IP counting from right to left to the first "." of the IP counting from left to right.
ipstr1=Trim(Replace(Left(getip,locations),".",""))
ipstr2=Right(getip,divide_locations)'Get the remaining value on the right side of the client after the first split
'If the IP is divided into 4 segments and each segment is less than 3 digits, add 0
if Len(ipstr1)="2" then ipstr1="0"&ipstr1 'The length is two, less than three, add a 0 before the string
if Len(ipstr1)="3" then ipstr1=ipstr1 'According to the above analogy
if Len(ipstr1)="1" then ipstr1="00"&ipstr1 'The ipstr1 at this time is the first segment of IP
ipstr12=checkip_right(ipstr2) 'The ipstr12 at this time is the second segment of the IP
ipstr122=checkip_left(ipstr2)
ipstr13=checkip_right(ipstr122) 'The ipstr13 at this time is the third segment of the IP
ipstr14=checkip_left(ipstr122) 'The ipstr14 at this time is the fourth segment of IP
if Len(ipstr14)="1" then ipstr14="00"&ipstr14 'Add 0 to the fourth segment of the obtained IP. This step is not necessary
if Len(ipstr14)="2" then ipstr14="0"&ipstr14
if Len(ipstr14)="3" then ipstr14=ipstr14
'response.write ipstr1&"<br>" 'Write the value of each segment after IP segmentation
'response.write ipstr12&"<br>"
'response.write ipstr13&"<br>"
'response.write ipstr14
allip=ipstr1&"."&ipstr12&"."&ipstr13&"."&ipstr14
finishgetip=left(allip,11)
dim ipaddr,iplocal,sqls
'The following SQL statement is to extract whether the left 11-bit value of the startip field is equal to the left 11-bit value of the client IP
sqls="SELECT country_state,areauser FROM ip WHERE Left(startip,11)='"&finishgetip&"'"
set rs=getaccessrecordset("#worldip.mdb",sqls,"1","1") 'Get the query value
if rs.eof then 'If no value equal to the client IP is found
showip=checkip_trueip() 'Assign the client IP to showip
ipaddr="Unknown region" 'Country or province
iplocal="Unknown location" 'Specific place
else
showip=checkip_trueip()
ipaddr=rs("country_state")
iplocal=rs("areauser")
end if
'response.write("Your IP is: "&showip&" ")
'response.write("You are from: "&ipaddr&" ")
'response.write("You are:"&iplocal)
rs.close
set rs=nothing
%>
<%="Your IP is:"&showip&" "%>
<%="You are from:"&ipaddr&" "%>
<%="You are:"&iplocal&"<br>"%>
If there is an error in the IP address, please contact me or download the database for correction, thank you! <br>
<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="203"><a href="Script56.rar">Download Script56.CHM</a>-->1.34M</td>
<td width="548">Introduction: Microsoft's help documentation, including VBscript syntax, JScript syntax, regular expressions </td>
<td width="3"> </td>
<td width="6"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><a href="ipsearch.rar">Download ASP global IP address search program</a></td>
<td>ASP+ACCESS size 401K; format rar</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><font color="#000099"> </font> <font color="#0000FF"> </font></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>If your IP is unknown, please submit your location if you wish:</td>
<td>
<form name="form1" method="post" action="postip.asp">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="21%"> Province: </td>
<td width="44%">
<input type="text" name="country_state">
</td>
<td width="35%"> </td>
</tr>
<tr>
<td width="21%">Specific location or network user:</td>
<td width="44%">
<input type="text" name="areauser">
</td>
<td width="35%">For example: Beijing Tsinghua University or Beijing Netcom users</td>
</tr>
<tr>
<td width="21%"> </td>
<td width="44%">
<input type="hidden" name="startip" value="<%=finishgetip&".000"%>">
<input type="hidden" name="endip" value="<%=finishgetip&".255"%>">
</td>
<td width="35%"> </td>
</tr>
<tr>
<td width="21%"> </td>
<td width="44%">
<input type="submit" name="Submit" value="Submit">
</td>
<td width="35%"> </td>
</tr>
</table>
</form>
</td>
<td> </td>
<td> </td>
</tr>
</table>
<%
end if
%>
</body>
</html>
Demo address: http://www.knowsky.com/ip