Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: naturegirl/BiscuitSpy
base: 0993f3c00f
...
head fork: naturegirl/BiscuitSpy
compare: 37b37635d5
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 10, 2014
root eclipse skeleton project a8991c5
root fix 37b3763
View
11 .classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="jnetpcap/jnetpcap.jar">
+ <attributes>
+ <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="BiscuitSpy/jnetpcap"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
31 .gitignore
@@ -0,0 +1,31 @@
+*.pydevproject
+.metadata
+.gradle
+.gitignore~
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+# sbteclipse plugin
+.target
+
+# TeXlipse plugin
+.texlipse
View
1  .gitignore~
@@ -0,0 +1 @@
+sdf
View
17 .project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>BiscuitSpy</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
BIN  jnetpcap/jnetpcap.jar
Binary file not shown
View
BIN  jnetpcap/libjnetpcap.so
Binary file not shown
View
139 src/com/BiscuitSpy/testing/Example.java
@@ -0,0 +1,139 @@
+package com.BiscuitSpy.testing;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jnetpcap.Pcap;
+import org.jnetpcap.PcapIf;
+import org.jnetpcap.packet.PcapPacket;
+import org.jnetpcap.packet.PcapPacketHandler;
+import org.jnetpcap.protocol.tcpip.Http;
+import org.jnetpcap.protocol.tcpip.Tcp;
+
+/**
+ * Here is the output generated by this example :
+ *
+ * Network devices found:
+ * #0: \Device\NPF_{BC81C4FC-242F-4F1C-9DAD-EA9523CC992D} [Intel(R) PRO/100 VE]
+ * #1: \Device\NPF_{E048DA7F-D007-4EEF-909D-4238F6344971} [VMware Virtual Ethernet Adapter]
+ * #2: \Device\NPF_{5B62B373-3EC1-460D-8C71-54AA0BF761C7} [VMware Virtual Ethernet Adapter]
+ * #3: \Device\NPF_GenericDialupAdapter [Adapter for generic dialup and VPN capture]
+ *
+ * Choosing 'Intel(R) PRO/100 VE) ' on your behalf:
+ * Received packet at Tue Nov 03 18:52:42 EST 2009 caplen=1362 len=1362 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=82 len=82 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=145 len=145 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=62 len=62 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=164 len=164 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=62 len=62 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=54 len=54 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=1073 len=1073 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=1514 len=1514 jNetPcap rocks!
+ * Received packet at Tue Nov 03 18:52:45 EST 2009 caplen=279 len=279 jNetPcap rocks!
+ */
+public class Example {
+
+ /**
+ * Main startup method
+ *
+ * @param args
+ * ignored
+ */
+ public static void main(String[] args) {
+ List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs
+ StringBuilder errbuf = new StringBuilder(); // For any error msgs
+
+ /***************************************************************************
+ * First get a list of devices on this system
+ **************************************************************************/
+ int r = Pcap.findAllDevs(alldevs, errbuf);
+ if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
+ System.err.printf("Can't read list of devices, error is %s", errbuf
+ .toString());
+ return;
+ }
+
+ System.out.println("Network devices found:");
+
+ int i = 0;
+ for (PcapIf device : alldevs) {
+ String description =
+ (device.getDescription() != null) ? device.getDescription()
+ : "No description available";
+ System.out.printf("#%d: %s [%s]\n", i++, device.getName(), description);
+ }
+
+ PcapIf device = alldevs.get(1); // We know we have atleast 1 device
+ System.out
+ .printf("\nChoosing '%s' on your behalf:\n",
+ (device.getDescription() != null) ? device.getDescription()
+ : device.getName());
+
+ /***************************************************************************
+ * Second we open up the selected device
+ **************************************************************************/
+ int snaplen = 64 * 1024; // Capture all packets, no trucation
+ int flags = Pcap.MODE_PROMISCUOUS; // capture all packets
+ int timeout = 10 * 1000; // 10 seconds in millis
+ Pcap pcap =
+ Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
+
+ if (pcap == null) {
+ System.err.printf("Error while opening device for capture: "
+ + errbuf.toString());
+ return;
+ }
+
+ /***************************************************************************
+ * Third we create a packet handler which will receive packets from the
+ * libpcap loop.
+ **************************************************************************/
+
+
+ PcapPacketHandler<String> jpacketHandler = new PcapPacketHandler<String>() {
+
+ final Tcp tcp = new Tcp();
+ final Http http = new Http();
+
+ public void nextPacket(PcapPacket packet, String user) {
+
+ /*
+ * A typical and common approach to getting headers from a packet is to
+ * chain them as a condition for the if statement. If we need to work
+ * with both tcp and http headers, for example, we place both of them on
+ * the command line.
+ */
+ if (packet.hasHeader(tcp) && packet.hasHeader(http)) {
+ /*
+ * Now we are guarranteed to have both tcp and http header peered. If
+ * the packet only contained tcp segment even though tcp may have http
+ * port number, it still won't show up here since headers appear right
+ * at the beginning of http session.
+ */
+
+ System.out.printf("http header::%s%n", http);
+
+ /*
+ * jNetPcap keeps track of frame numbers for us. The number is simply
+ * incremented with every packet scanned.
+ */
+
+ }
+ }
+ };
+
+ /***************************************************************************
+ * Fourth we enter the loop and tell it to capture 10 packets. The loop
+ * method does a mapping of pcap.datalink() DLT value to JProtocol ID, which
+ * is needed by JScanner. The scanner scans the packet buffer and decodes
+ * the headers. The mapping is done automatically, although a variation on
+ * the loop method exists that allows the programmer to sepecify exactly
+ * which protocol ID to use as the data link type for this pcap interface.
+ **************************************************************************/
+ pcap.loop(-1, jpacketHandler, "jNetPcap rocks!");
+
+ /************************************************* **************************
+ * Last thing to do is close the pcap handle
+ **************************************************************************/
+ pcap.close();
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.