Search Results

Search found 6 results on 1 pages for 'jpcap'.

Page 1/1 | 1 

  • Creating a Reverse Proxy using Jpcap

    - by Ramon Marco Navarro
    I need to create a program that receives HTTP request and forwards those requests to the web servers. I have successfully made this using only Java Sockets but the client needed the program to be implemented in Jpcap. I'd like to know if this is possible and what literature I should be reading for this project. This is what I have now by stitching together pieces from the Jpcap tutorial: import java.net.InetAddress; import java.io.*; import jpcap.*; import jpcap.packet.*; public class Router { public static void main(String args[]) { //Obtain the list of network interfaces NetworkInterface[] devices = JpcapCaptor.getDeviceList(); //for each network interface for (int i = 0; i < devices.length; i++) { //print out its name and description System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")"); //print out its datalink name and description System.out.println(" datalink: "+devices[i].datalink_name + "(" + devices[i].datalink_description+")"); //print out its MAC address System.out.print(" MAC address:"); for (byte b : devices[i].mac_address) System.out.print(Integer.toHexString(b&0xff) + ":"); System.out.println(); //print out its IP address, subnet mask and broadcast address for (NetworkInterfaceAddress a : devices[i].addresses) System.out.println(" address:"+a.address + " " + a.subnet + " "+ a.broadcast); } int index = 1; // set index of the interface that you want to open. //Open an interface with openDevice(NetworkInterface intrface, int snaplen, boolean promics, int to_ms) JpcapCaptor captor = null; try { captor = JpcapCaptor.openDevice(devices[index], 65535, false, 20); captor.setFilter("port 80 and host 192.168.56.1", true); } catch(java.io.IOException e) { System.err.println(e); } //call processPacket() to let Jpcap call PacketPrinter.receivePacket() for every packet capture. captor.loopPacket(-1,new PacketPrinter()); captor.close(); } } class PacketPrinter implements PacketReceiver { //this method is called every time Jpcap captures a packet public void receivePacket(Packet p) { JpcapSender sender = null; try { NetworkInterface[] devices = JpcapCaptor.getDeviceList(); sender = JpcapSender.openDevice(devices[1]); } catch(IOException e) { System.err.println(e); } IPPacket packet = (IPPacket)p; try { // IP Address of machine sending HTTP requests (the client) // It's still on the same LAN as the servers for testing purposes. packet.dst_ip = InetAddress.getByName("192.168.56.2"); } catch(java.net.UnknownHostException e) { System.err.println(e); } //create an Ethernet packet (frame) EthernetPacket ether=new EthernetPacket(); //set frame type as IP ether.frametype=EthernetPacket.ETHERTYPE_IP; //set source and destination MAC addresses // MAC Address of machine running reverse proxy server ether.src_mac = new MacAddress("08:00:27:00:9C:80").getAddress(); // MAC Address of machine running web server ether.dst_mac = new MacAddress("08:00:27:C7:D2:4C").getAddress(); //set the datalink frame of the packet as ether packet.datalink=ether; //send the packet sender.sendPacket(packet); sender.close(); //just print out a captured packet System.out.println(packet); } } Any help would be greatly appreciated. Thank you.

    Read the article

  • decompiling a DNS packet

    - by rgksugan
    I am trying to catch DNS packets which are sent from my system using Jpcap API. I have got an dns packet. I want to retrieve the ip address for which the DNS lookup is made. How can i get that?

    Read the article

  • Oracle java 6 on ubuntu

    - by Shanee
    The java library I need (jpcap) only works on java 6, it won't work with java 7 (and I have tried :( ), is it still possible to install java 6 on ubuntu? Only according to https://help.ubuntu.com/community/Java#Choosing_the_default_Java_to_use, 'Oracle (Sun) Java 6 is no longer available to be distributed by Ubuntu, because of license issues' I've tried to use the instructions on the same site but they don't seem to work... "./jre-6u34-linux-i586.bin" doesn't seem to do anything! Thanks!

    Read the article

  • Start tomcat webapp with root privileges

    - by Hagay Myr
    I built a webapp that uses libpcap (via jpcap). In order to be able to get the network interfaces list or to bind to a network interface, the application (in this case a webaap that runs from tomcat server) must be running with root privileges. During development I simply ran Eclipse with root privileges (sudo eclipse) and my webapp worked just fine with Eclipse's local tomcat server. However, when I try to deploy my webapp to the "real" tomcat server, it isn't working. I Also tried to start the tomcat6 service with sudo and changed the TOMCAT6_USER definition (defined in /etc/init.d/tomcat6) from "tomcat6" to "root" but it made no difference. What should I do to make it work?

    Read the article

  • capturing dns packets using java

    - by rgksugan
    I want to log the websites visited in a system. So i decided to record the packets send by the system. I am using Jpcap API. I am able to record a lot of packets. Now what i want to do is i want to filter only DNS packets. I think that will be able to log the websites. I want a way to filter the DNS packets. How can I do it?

    Read the article

1