I've asked this to Jnetpcap forum. And didn't get any response. I've been trying to get the website name from the request/ response packet. This is what I've tried:
PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {
final Tcp tcp = new Tcp();
final Http http = new Http();
final Ip4 ip = new Ip4();
public void nextPacket(PcapPacket packet, String user) {
if (packet.hasHeader(http)) {
packet.getHeader(http);
final String content_length = http.fieldValue(Response.Content_Length);
final String response_code = http.fieldValue(Response.ResponseCode);
//Find if the given packet is a Request/Response Pkt : First get the TCP header
packet.getHeader(tcp);
Integer int_tcp_source = new Integer(tcp.source());
Integer int_tcp_destination = new Integer(tcp.destination());
if(int_tcp_source!=80 && content_length==null){
//It is a Request pkt :
packet.getHeader(http);
final String ref = http.fieldValue(Request.Referer);
final String req_url = http.fieldValue(Request.RequestUrl);
String page_url = http.fieldValue(Request.Host);
System.out.printf("\n Referer " +ref +req_url );//Get the URL
System.out.printf("\nHost " +page_url);
}
}
}
};
But it doesn't even go inside the :
if (packet.hasHeader(http)) {
I'm using windows laptop and wireless connection.
if I try:
if (packet.hasHeader(ip)) {//Ip4
I can get into the if block and can retrieve the source and destination IP address.
I basically need to do the same thing as http://jnetpcap.com/?q=node/937.
I'm really stuck and really need someone's help.
Or simply can someone please help me to figure out how to get the website name from the packet? some code snippet would be great.
Can anyone please help.
Thanks in advance.