Many friends may want to make an IP query. This code is still relatively simple. First of all, you have to have an IP address database. You can download it on my website. Download the address: http://www.brsky.net.net /data/ipaddress.mdb, of course, I do not guarantee that this is the latest. Below I give a code to query the IP address:
Demonstration of this page: http://www.brsky.net/sip.asp
<%
"Connect the database
dim conn, connstr, db
db = "data/ipaddress.mdb"
Set conn = server.createObject ("Adodb.connection")
Connstr = "Provider = Microsoft.jet.OLEDB.4.0; Data Source =" & Server.MAPPATH ("" & DB & "")
conn.open connstr
%>
The following part is a submission form for input IP data: This data is submitted to this page
<form id = "form1" name = "form1" method = "post" action = "">
<Label>
Please enter the ip to be query
<input name = "ip" type = "text" id = "ip" />
</label>
<Label>
<input type = "submit" name = "submit" value = "Query" />
</label>
</form>
"The following is the query and display code
<%
If not request.form ("IP") = "THEN" if the form is submitted to the data, it is processed and processed
sip = trim (request.form ("IP"))
cip = split (sip, ".")
If ubound (CIP) <3te "If the IP data submitted is less than 4 bits, make up
Redim Preserve CIP (3) "redefine the array and retain the original value
for i = 3 to ubound (CIP) Step -1
cip (i) = 0
next
end if
For i = 0 to 3 "Check the array elements as a value character here. If not, you can use the maximum and minimum value of the IP rules separately. I only use the minimum value here.
if not isnumeric (cip (i)) then cip (i) = 0
next
IP = 256*256*256*CIP (0) 256*256*CIP (1) 256*CIP (2) CIP (3) -1
DIM RS, SQL, Country, City, City
Set rs = server.createObject ("Adodb.oldSet")
SQL = "Select * From Address where ip1 <=" & ip & "and ip2> =" & ip
RS.Oopen SQL, CONN, 1,1
if rs.eof then
City = "Unknown"
Country = "Unknown"
else
City = RS ("City")
Country = RS ("Country")
end if
RS.Close
set rs = Nothing
Response.write "The IP you want to query is" & sip & ", from" & country & city
end if
%>