Adding feature to hold multiple hostnames and lists of packet orders in FlowPattern...
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / Main.java
1 package edu.uci.iotproject;
2
3 import org.pcap4j.core.*;
4
5 import java.io.EOFException;
6 import java.net.UnknownHostException;
7 import java.util.*;
8 import java.util.concurrent.TimeoutException;
9
10 /**
11  * This is a system that reads PCAP files to compare
12  * patterns of DNS hostnames, packet sequences, and packet
13  * lengths with training data to determine certain events
14  * or actions for smart home devices.
15  *
16  * @author Janus Varmarken
17  * @author Rahmadi Trimananda (rtrimana@uci.edu)
18  * @version 0.1
19  */
20 public class Main {
21
22
23     public static void main(String[] args) throws PcapNativeException, NotOpenException, EOFException, TimeoutException, UnknownHostException {
24         final String fileName = args.length > 0 ? args[0] : "/home/rtrimana/pcap_processing/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/wlan1.local.remote.dns.pcap";
25         final String trainingFileName = "./pcap/TP_LINK_LOCAL_ON.pcap";
26         //final String trainingFileName = "./pcap/TP_LINK_REMOTE_ON.pcap";
27
28         // ====== Debug code ======
29         PcapHandle handle;
30         PcapHandle trainingPcap;
31         try {
32             handle = Pcaps.openOffline(fileName, PcapHandle.TimestampPrecision.NANO);
33             trainingPcap = Pcaps.openOffline(trainingFileName, PcapHandle.TimestampPrecision.NANO);
34         } catch (PcapNativeException pne) {
35             handle = Pcaps.openOffline(fileName);
36             trainingPcap = Pcaps.openOffline(trainingFileName);
37         }
38
39         // TODO: The followings are the way to extract multiple hostnames and their associated packet lengths lists
40         //List<String> list = new ArrayList<>();
41         //list.add("events.tplinkra.com");
42         //FlowPattern fp = new FlowPattern("TP_LINK_LOCAL_ON", list, trainingPcap);
43         //List<String> list2 = new ArrayList<>();
44         //list2.add("devs.tplinkcloud.com");
45         //list2.add("events.tplinkra.com");
46         //FlowPattern fp3 = new FlowPattern("TP_LINK_REMOTE_ON", list2, trainingPcap);
47
48         FlowPattern fp = new FlowPattern("TP_LINK_LOCAL_ON", "events.tplinkra.com", trainingPcap);        
49         FlowPatternFinder fpf = new FlowPatternFinder(handle, fp);
50         fpf.start();
51
52         // ========================
53     }
54 }