ip地址查询的实现方法可能和大家自己的想法不是一样的。大家可以看看一般的实现方法。
ipqueary.jsp
<%@page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<jsp:usebean id="user" scope="page" class="user.db" />
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>ip查询</title>
</head>
<link href="css/style.css" _fcksavedurl=""css/style.css"" _fcksavedurl=""css/style.css"" rel=stylesheet type="text/css">
<body>
<div align="center"><font color="#0000ff" size="2"><strong>ip查询结果</strong></font></div>
<br>
<%
connection con = user.getconn() ;
statement stmt=con.createstatement(resultset.type_scroll_insensitive,resultset.concur_read_only);
string sql;
resultset rs;
if( request.getparameter("ip1") != null){
string number1 = request.getparameter("ip1").trim();
string number2 = request.getparameter("ip2").trim();
string number3 = request.getparameter("ip3").trim();
string number4 = request.getparameter("ip4").trim();
string number = number1+"."+number2+"."+number3+"."+number4;
sql="select * from ipaddr where beginaddr<='"+number+"' and endaddr>='"+number+"' and left(beginaddr,3)='"+number1+"' and left(endaddr,3)='"+number1+"' and substring(beginaddr,5,3)='"+number2+"' and '"+number2+"'=substring(endaddr,5,3) and substring(beginaddr,9,3)='"+number3+"' and '"+number3+"'=substring(endaddr,9,3)";
rs=stmt.executequery(sql);
if(!rs.next()){
sql="select * from ipaddr where beginaddr<='"+number+"' and endaddr>='"+number+"' and left(beginaddr,3)='"+number1+"' and left(endaddr,3)='"+number1+"' and substring(beginaddr,5,3)='"+number2+"' and '"+number2+"'=substring(endaddr,5,3)";
rs=stmt.executequery(sql);
if(!rs.next()){
sql="select * from ipaddr where beginaddr<='"+number+"' and endaddr>='"+number+"' and left(beginaddr,3)='"+number1+"' and left(endaddr,3)='"+number1+"'";
rs=stmt.executequery(sql);
if(!rs.next()){
sql="select * from ipaddr where beginaddr<='"+number+"' and endaddr>='"+number+"'";
rs=stmt.executequery(sql);
}
}
}
if(rs.next()){
%>
</div>
<table border=1 width=500 align="center" >
<tr>
<td width=100% colspan=2 align=middle height=22 class=btn>搜索结果:</td>
</tr>
<tr>
<td width=28% align=middle height=22 class=btn>你要搜索的ip地址:</td>
<td width=72% align=middle height=22 class=btn><%=number%></td>
</tr>
<tr>
<td width=28% align=middle height=22 class=btn>查询结果:</td>
<td width=72% align=middle height=22 class=btn><%=rs.getstring("country")%><font color="#ff0000">:</font><%=rs.getstring("city")%><font color="#ff0000">:</font><%=rs.getstring("detail")%></td>
</tr>
</table>
<%
}else
{
%>
<table border=1 cellpadding=4 width=500 align=center>
<tr>
<td width='100%' colspan=2 align=middle height=22 class=btn>搜索结果:</td>
</tr>
<tr>
<td width=28% align=middle height=22 bgcolor=#eff1f3 class=btn>你要搜索的ip地址:</td>
<td width=72% align=middle height=22 bgcolor=#eff1f3 class=btn><%=number%></td>
</tr>
<tr>
<td width=28% align=middle height=22 bgcolor=#eff1f3 class=btn>查询结果:</td>
<td width=72% align=middle height=22 bgcolor=#eff1f3 class=btn>没有找到!!</td>
</tr>
</table>
<%
}
}%>
</html>
新闻热点
疑难解答