Main.java: cleanup - get rid of old, commented sample/debug code
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / Main.java
1 package edu.uci.iotproject;
2
3 import edu.uci.iotproject.analysis.TriggerTrafficExtractor;
4 import edu.uci.iotproject.io.TriggerTimesFileReader;
5 import org.pcap4j.core.*;
6 import org.pcap4j.packet.namednumber.DataLinkType;
7
8 import java.io.EOFException;
9 import java.net.UnknownHostException;
10 import java.time.Instant;
11 import java.util.*;
12 import java.util.concurrent.TimeoutException;
13
14 /**
15  * This is a system that reads PCAP files to compare
16  * patterns of DNS hostnames, packet sequences, and packet
17  * lengths with training data to determine certain events
18  * or actions for smart home devices.
19  *
20  * @author Janus Varmarken
21  * @author Rahmadi Trimananda (rtrimana@uci.edu)
22  * @version 0.1
23  */
24 public class Main {
25
26
27     public static void main(String[] args) throws PcapNativeException, NotOpenException, EOFException, TimeoutException, UnknownHostException {
28         // -------- 07-19-2018 --------
29         TriggerTimesFileReader ttfr = new TriggerTimesFileReader();
30 //        List<Instant> triggerTimes = ttfr.readTriggerTimes("/Users/varmarken/Downloads/tplink-feb-13-2018.timestamps", false);
31         List<Instant> triggerTimes = ttfr.readTriggerTimes("/Users/varmarken/temp/UCI IoT Project/June2018 experiments/tplink/tplink-june-14-2018-timestamps.txt", false);
32 //        String pcapFile = "/Users/varmarken/Development/Repositories/UCI/NetworkingGroup/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap";
33         String pcapFile = "/Users/varmarken/temp/UCI IoT Project/June2018 experiments/tplink/tplink.wlan1.local.pcap";
34         String tpLinkPlugIp = "192.168.1.159";
35         TriggerTrafficExtractor tte = new TriggerTrafficExtractor(pcapFile, triggerTimes, tpLinkPlugIp);
36 //        final PcapDumper outputter = Pcaps.openDead(DataLinkType.EN10MB, 65536).dumpOpen("/Users/varmarken/temp/traces/output/tplink-filtered.pcap");
37         final PcapDumper outputter = Pcaps.openDead(DataLinkType.EN10MB, 65536).dumpOpen("/Users/varmarken/temp/UCI IoT Project/June2018 experiments/tplink/tplink-filtered.pcap");
38         DnsMap dnsMap = new DnsMap();
39         TcpReassembler tcpReassembler = new TcpReassembler();
40         tte.performExtraction(pkt -> {
41             try {
42                 outputter.dump(pkt);
43             } catch (NotOpenException e) {
44                 e.printStackTrace();
45             }
46         }, dnsMap, tcpReassembler);
47         outputter.flush();
48         outputter.close();
49         // ----------------------------
50     }
51
52 }
53
54
55 // TP-Link MAC 50:c7:bf:33:1f:09 and usually IP 192.168.1.159 (remember to verify per file)