PaServlet.java
上传用户:xie_wn
上传日期:2022-03-04
资源大小:941k
文件大小:5k
源码类别:

网络截获/分析

开发平台:

Java

  1. package com.servlet;
  2. import java.io.IOException;
  3. import javax.servlet.ServletException;
  4. import javax.servlet.http.HttpServlet;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.apache.commons.httpclient.NameValuePair;
  8. import au.id.jericho.lib.html.Segment;
  9. import au.id.jericho.lib.html.Source;
  10. import com.util.ClientUtil;
  11. import com.util.HtmlUtil;
  12. /**
  13.  * Servlet implementation class PaServlet
  14.  */
  15. public class PaServlet extends HttpServlet {
  16. String zhi;
  17. protected void service(HttpServletRequest request, HttpServletResponse response)
  18. throws ServletException, IOException {
  19. // TODO Auto-generated method stub
  20.    request.setCharacterEncoding("GBK");
  21.    String sj=request.getParameter("sj");
  22.    zhi=request.getParameter("zhi");
  23.    System.out.println(zhi);
  24.    if("".equals(sj) || "".equals(zhi))
  25.    {
  26.   response.sendRedirect(request.getContextPath()+"/jsp") ;
  27.    }
  28.    else if("ip".equals(sj))
  29.    {
  30.    ipSend(request,response);
  31.    }
  32.    else if("sjj".equals(sj))
  33.    {
  34.    sjSend(request,response);
  35.    }
  36.    else if("sf".equals(sj))
  37.    {
  38.    sfSend(request,response);
  39.    }
  40.    else if("ss".equals(sj))
  41.    {
  42.    ssSend(request,response);
  43.    }
  44.    
  45. }
  46. protected void ipSend(HttpServletRequest request, HttpServletResponse response)
  47. throws ServletException, IOException {
  48. // TODO Auto-generated method stub
  49.    String url="http://www.ip138.com/ips.asp";
  50.        NameValuePair nvp1=new NameValuePair("action","2");
  51.        NameValuePair nvp2=new NameValuePair("ip",zhi);
  52.        NameValuePair[] aa=new  NameValuePair[]{nvp1,nvp2};
  53.        ClientUtil cu=new ClientUtil();
  54.        Source s=new Source(cu.post(url, aa));
  55.          //System.out.println(s.toString());
  56.        Segment sg=HtmlUtil.getSegment("table", 2, s);
  57.      //  System.out.println(sg.toString());
  58.        Segment td=HtmlUtil.getSegment2("td", 2, sg);
  59.        Segment ul=HtmlUtil.getSegment2("ul", 0, td);
  60.       request.setAttribute("ip", zhi);
  61.       request.setAttribute("nr", ul.toString());
  62.       request.getRequestDispatcher("/jsp/ip.jsp").forward(request, response);
  63.       
  64. }
  65. protected void sjSend(HttpServletRequest request, HttpServletResponse response)
  66. throws ServletException, IOException {
  67. // TODO Auto-generated method stub
  68.   String url="http://www.ip138.com:8080/search.asp";
  69.        NameValuePair nvp1=new NameValuePair("action","mobile");
  70.        NameValuePair nvp2=new NameValuePair("mobile",zhi);
  71.        NameValuePair[] aa=new  NameValuePair[]{nvp1,nvp2};
  72.        ClientUtil cu=new ClientUtil();
  73.        Source s=new Source(cu.post(url, aa));
  74.         System.out.println(s.toString());
  75.        Segment sg=HtmlUtil.getSegment("table", 1, s);
  76.        //归属地  gsd 卡类型  klx 
  77.        String gsd=HtmlUtil.getSegment2("td",4, sg).extractText();
  78.        String klx=HtmlUtil.getSegment2("td",6, sg).extractText();
  79.        String qh=HtmlUtil.getSegment2("td",8, sg).extractText();
  80.        String yb=HtmlUtil.getSegment2("td",10, sg).extractText();
  81.        yb=yb.split(" ")[0];
  82.        request.setAttribute("sj", zhi);
  83.        request.setAttribute("gsd", gsd);
  84.        request.setAttribute("klx", klx);
  85.        request.setAttribute("qh", qh);
  86.        request.setAttribute("yb", yb);
  87.        request.getRequestDispatcher("/jsp/sj.jsp").forward(request, response);
  88. }
  89. protected void sfSend(HttpServletRequest request, HttpServletResponse response)
  90. throws ServletException, IOException {
  91. // TODO Auto-generated method stub
  92.  String sf=request.getParameter("sf");
  93.  String url="http://qq.ip138.com/idsearch/index.asp";
  94.       NameValuePair nvp1=new NameValuePair("action","idcard");
  95.       NameValuePair nvp2=new NameValuePair("userid","230105198306031915");
  96.       NameValuePair[] aa=new  NameValuePair[]{nvp1,nvp2};
  97.       ClientUtil cu=new ClientUtil();
  98.       Source s=new Source(cu.post(url, aa));
  99.       Segment sg=HtmlUtil.getSegment("table", 4, s);
  100.       //性别   出生日期   发证地  现为
  101.       String xb=HtmlUtil.getSegment2("td",1, sg).extractText();
  102.       String csrq=HtmlUtil.getSegment2("td",3, sg).extractText();
  103.       String fzd=HtmlUtil.getSegment2("td",5, sg).extractText();
  104.       String xw=HtmlUtil.getSegment2("td",7, sg).extractText();
  105.       request.setAttribute("xb", xb);
  106.       request.setAttribute("csrq", csrq);
  107.       request.setAttribute("xw", xw);
  108.       request.setAttribute("fzd", fzd);
  109.       request.getRequestDispatcher("/jsp/sf.jsp").forward(request, response); 
  110. }
  111. protected void ssSend(HttpServletRequest request, HttpServletResponse response)
  112. throws ServletException, IOException {
  113. // TODO Auto-generated method stub
  114. }
  115. }