📄 ipcheckout.java
字号:
//inCheckOut.java
import java.io.*;
import java.net.*;
import java.util.StringTokenizer;
import javax.servlet.*;
import javax.servlet.http.*;
public class ipCheckOut extends HttpServlet
{
String inputIP=null;
short []a;
short []b;
short []c;
short []d;
String data[];
int i;
FileReader filein=null;
BufferedReader filedata=null;
String IPlist="";
public void service(HttpServletRequest rq,HttpServletResponse rp) throws
ServletException, IOException
{
rp.setContentType("text/html");
PrintWriter out=rp.getWriter();
String hname=rp.getParameter("hname");
String IPfname=rp.getParameter("fname");
out.println("<html><head><title>检查访问的IP地址是国内还是国外</title>");
out.println("</head>");
out.println("<body bgcolor='#808000'>");
out.println("<p align='center'><font color='#FFFF00' size='4'>查询结果</font></p>");
go(hname,IPfname,out);
out.println("</table>");
out.println("</body>");
out.println("</html>");
}
public void go(String hname,String IPfname,PrintWriter out)throws IOException
{
InetAddress ipHost;
String hoststr=null;
int dash=0;
try{
if(hname!=null)
{
ipHost=InetAddress.getByName(hname);
out.println("<table border='0' width='100%'>");
out.println("<tr>");
out.println("<td width='50%'><font color='#00FF00' size='3'>");
out.println("Host name:" + ipHost.getHostName()+"</font></td>");
out.println("<td width='50%'><font color='#00FF00' size='3'>");
out.println("主机名:" + ipHost.getHostName()+"</font></td>");
out.println("</tr>");
}
else
{
out.println("Please input an hostname"+"<br>");
return;
}
if(IPfname != null)
freeOrFee(IPfname,out);
}catch(UnknownHostException e)
{
out.println("this hostname is illegal."+"<br>");
}
}
public void freeOrFee(String IPfname,PrintWriter out) throws IOException
{
String str=null;
String startIP=null;
String endIP=null;
a=new short[5];
b=new short[5];
c=new short[5];
d=new short[5];
boolean free=false;
URL fileURL=null;
try{
fileURL=new URL(IPfname);
InputStream is =fileURL.openStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader filedata = new BufferedReader(isr);
int i=0;
while((str=filedata.readLine())!=null)
{
startIP=str.substring(0,18);
startIP=startIP.trim();
endIP=str.substring(18,36);
endIP=endIP.trim();
stringToInt(startIP,0);
stringToInt(endIP,1);
stringToInt(inputIP,2);
for (int j=3;j<=4;j++)
{
a[j]=shortOrShort(a[j-3],a[j-2]);
b[j]=shortOrShort(b[j-3],b[j-2]);
c[j]=shortOrShort(c[j-3],c[j-2]);
d[j]=shortOrShort(d[j-3],d[j-2]);
}
if((a[3]==a[4])&&(b[3]==b[4])&&(c[3]==c[4])&&(d[3]==d[4]))
{
free=true;
out.println("<tr>");
out.println("<td width='50%'><font color='#00FF00' size='3'>");
out.println("This address is free." +" </font></td>");
out.println("<td width='50%'><font color='#00FF00' size='3'>");
out.println("这个地址是免费的。"+"</font></td>");
out.println("</tr>");
break;
}
}
if(!free)
{
out.println("<tr>");
out.println("<td width='50%'><font color='#00FF00' size='3'>");
out.println("This address is on fee." + "</font></td>");
out.println("<td width='50%'><font color='#00FF00' size='3'>");
out.println("这个地址是付费的。"+"</font></td>");
out.println("</tr>");
}
}catch (IOException e){out.println(e.toString()+"<br>");}
}
public short shortOrShort(short x,short y)
{
short z=0;
z=(short)(x|y);
return z;
}
public void stringToInt(String str,int j)
{
StringTokenizer st=new StringTokenizer(str,".");
a[j]=Short.parseShort(st.nextToken());
b[j]=Short.parseShort(st.nextToken());
c[j]=Short.parseShort(st.nextToken());
d[j]=Short.parseShort(st.nextToken());
if(st.hasMoreToken())
{
handleArg(st.nextToken(""));
}
else
{
handleArg(null);
}
}
public void handleArg(String s){}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -