Home  >  Q&A  >  body text

windows - java用jpcap怎么识别出http和https的数据包?

问题简述:
利用java的第三方库jpcap写抓包程序,求解怎么识别出http和https的数据包(就只要能判断出是http协议或https协议即可)。

测试的解法:
1.在tcp包(jpcap自带TCPPacket类比较方便识别tcp包)的基础上用80端口和443端口区分http和https,但是连tcp都识别成http或https了(不成功)。
2.设法找出http或https特有而tcp没有的字段,未能找出。

代码示意(未完成):
` else if(packet instanceof jpcap.packet.ICMPPacket) {

                  packetprocol = "ICMP";
                  r.addElement(packetprocol);
              }
              else if(packet instanceof jpcap.packet.TCPPacket) {
                  TCPPacket tcppacket = (TCPPacket)packet;
                  //if((tcppacket.src_port==80||tcppacket.dst_port==80)&&tcppacket.) {
                      packetprocol = "HTTP";
                      r.addElement(packetprocol);
                  }else if(tcppacket.src_port==443||tcppacket.dst_port==443) {
                      packetprocol = "HTTPS";
                      r.addElement(packetprocol);
                  }
                  else {
                      packetprocol = "TCP";
                      r.addElement(packetprocol);
                  }` 
巴扎黑巴扎黑2764 days ago456

reply all(1)I'll reply

  • 阿神

    阿神2017-04-18 10:56:29

    Temporary solution:
    Determine whether the data field of the captured tcp packet contains the "HTTP" string.
    Disadvantages:
    1. After comparing with wireshark, we found that some tcp packets in the data field of wireshark have HTTP and are recognized as tcp instead of http (I don’t know how wireshark parses it).
    2. It feels like judgments will be missed and not accurate enough.
    Continue to look for better solutions and look forward to answers!

    reply
    0
  • Cancelreply