1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
101 102 103 104 105 106 107 108 109 110
111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126
|
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class WHOISServlet extends HttpServlet
{
public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String input = req.getParameter ("input");
String requestURI = req.getRequestURI();
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
if (input==null)
{
pw.println ("<br>Improper Host/Domain Name - Please Re-try<br>");
pw.close();
return;
}
pw.println ("<html>");
pw.println ("<frameset rows='15%,65%,20%'>");
pw.print ("<frame src='");
pw.print (requestURI+"?input="+input+"&todo=time");
pw.println ("'>");
pw.print ("<frame src='");
pw.print (requestURI+"?input="+input+"&todo=whois");
pw.println ("'>");
pw.print ("<frame src='");
pw.print (requestURI+"?input="+input+"&todo=finger-query");
pw.println ("'>");
pw.println ("</frameset>");
pw.println ("</html>");
pw.flush();
pw.close();
} // end doPost
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String input = req.getParameter ("input");
String todo = req.getParameter ("todo");
WHOIS whois = new WHOIS();
if (todo.equals("time"))
doTime (input, whois, res);
else if (todo.equals("whois"))
doWhoIs (input, whois, res);
else if (todo.equals("finger-query"))
doFingerQuery (input, whois, res);
} // end doGet
private void doTime (String input, WHOIS whois, HttpServletResponse res) throws IOException
{
String inputDomainName = getDomainName (input);
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println ("<html>");
pw.println ("<body bgcolor='ff0000' text='ffffff'>");
if (!input.equals(inputDomainName))
{
pw.println ("Contacting Host("+input+") for Day-Time Information...<br><br>");
pw.flush();
res.flushBuffer();
pw.println (whois.getDaytimeInfo(input));
pw.println ("<br>");
}
else
pw.println ("No Host to Contact for Day-Time Information<br>");
pw.println ("</body>");
pw.println ("</html>");
pw.flush();
pw.close();
} // end doTime
private void doWhoIs (String input, WHOIS whois, HttpServletResponse res) throws IOException
{
String inputDomainName = getDomainName (input);
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println ("<html>");
pw.println ("<body bgcolor='009d00' text='ffffff'>");
pw.println ("Contacting Internic Server for Domain Information("+inputDomainName+")...<br><br>");
pw.flush();
res.flushBuffer();
pw.println (whois.getDomainInfo(inputDomainName,"<br>\n"));
pw.println ("</body>");
pw.println ("</html>");
pw.flush();
pw.close();
} // end doWhoIs
private void doFingerQuery (String input, WHOIS whois, HttpServletResponse res) throws IOException
{
String inputDomainName = getDomainName (input);
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println ("<html>");
pw.println ("<body bgcolor='0000ff' text='ffffff'>");
if (!input.equals(inputDomainName))
{
pw.println ("Contacting Host("+input+") for User Information...<br><br>");
pw.flush();
res.flushBuffer();
pw.println (whois.getFingerQueryInfo(input,"","<br>\n"));
pw.println ("<br>");
}
else
pw.println ("No Host to Contact for User Information<br>");
pw.println ("</body>");
pw.println ("</html>");
pw.flush();
pw.close();
} // end doFingerQuery
private String getDomainName (String hostOrDomainName)
{
if (hostOrDomainName.startsWith("!"))
return hostOrDomainName;
int i = hostOrDomainName.lastIndexOf (".");
if (i<=0)
return null;
i = hostOrDomainName.lastIndexOf (".", i-1);
return hostOrDomainName.substring (i+1);
} // end getDomainName
} // end class WHOISServlet
|