1 package edu.uci.iotproject;
3 import java.util.ArrayList;
8 * Entry point of the application.
10 * @author Janus Varmarken
13 private static int counter = 0;
15 public static void main(String[] args) throws Exception {
16 System.out.println("it works");
17 //String file = "/scratch/traffic_measurements/Switches-Feb2018/wemo/wlan1/wlan1.setup.pcap";
18 String file = "/home/rtrimana/pcap_processing/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap";
21 Pcap data = Pcap.fromFile(file);
23 List<Pcap.Packet> listPacket = data.packets();
24 System.out.println("Number of packets: " + listPacket.size());
25 System.out.println("===================");
26 for(Pcap.Packet packet : listPacket) {
27 System.out.print("#" + counter++ + "\n");
28 if (packet._root().hdr().network() == Pcap.Linktype.ETHERNET) {
29 EthernetFrame eFrame = (EthernetFrame) packet.body();
30 if (eFrame.etherType() == EthernetFrame.EtherTypeEnum.IPV4) {
31 Ipv4Packet ip4Packet = (Ipv4Packet) eFrame.body();
32 byte[] srcIp = ip4Packet.srcIpAddr();
33 byte[] dstIp = ip4Packet.dstIpAddr();
34 System.out.println("Byte length source: " + srcIp.length + " Byte length dest: " + dstIp.length);
35 System.out.print("Source: ");
36 for(int i = 0; i < srcIp.length; i++) {
37 System.out.print(Byte.toUnsignedInt(srcIp[i]));
38 if(i < srcIp.length-1)
39 System.out.print(".");
41 System.out.print(" - Dest: ");
42 for(int i = 0; i < dstIp.length; i++) {
43 System.out.print(Byte.toUnsignedInt(dstIp[i]));
44 if(i < dstIp.length-1)
45 System.out.print(".");
47 System.out.println("\n");
53 } catch (Exception e) {
58 private String cloudIPAddress(String hostName) {
59 if (hostName.equals("events.tplinkra.com"))
60 return "205.251.203.26";
65 // TODO move to separate class
66 // Add parameter that is the trace to be analyzed (most like the pcap library's representation of a flow)
67 public String findPattern(Map<String, List<Integer>> hostnameToPacketLengths, String smartPlugIp) {
69 // No difference, output "Complete match"
70 // If difference, output <Packet no, deviation from expected> for each packet