我正在開發一個應用程序來捕獲所有的HTTP URL。我用pcap.LOOP_INFINATE持久捕獲,但是當我在谷歌上搜索時,它不捕獲任何數據包。請給我一個解決方案。無法使用jnetpcap捕獲谷歌搜索URL
這是我的示例代碼:
int snaplen = 64 * 1024;
int flags = Pcap.MODE_PROMISCUOUS;
int timeout = 10*1000;
Pcap pcap = Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {
final Tcp tcp = new Tcp();
final Ip4 ip = new Ip4(); Arp arp=new Arp();Payload payload = new Payload();
Ethernet eth=new Ethernet();Http http = new Http();Udp udp=new Udp();
public void nextPacket(PcapPacket packet, String user) {
if (packet.hasHeader(tcp) && packet.hasHeader(http)) {
if(tcp.destination() == 80) {
if(http.hasField(Http.Request.Accept) && http.fieldValue(Http.Request.Accept).contains("text/html"))
{
String host = http.fieldValue(Http.Request.Host);
String url = host + http.fieldValue(Http.Request.RequestUrl);
String referer = http.fieldValue(Http.Request.Referer);
System.out.println("Request: " +" - " + url);
}
}
}
}
};
pcap.loop(pcap.LOOP_INFINATE,jpacketHandler, null);
谷歌搜索使用https,例如端口443而不是端口80.它被加密,所以你不會通過簡單的數據包捕獲獲得可用的數據。 –