1 package edu.uci.iotproject;
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;
8 import java.io.EOFException;
9 import java.net.UnknownHostException;
10 import java.time.Instant;
12 import java.util.concurrent.TimeoutException;
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.
20 * @author Janus Varmarken
21 * @author Rahmadi Trimananda (rtrimana@uci.edu)
27 public static void main(String[] args) throws PcapNativeException, NotOpenException, EOFException, TimeoutException, UnknownHostException {
28 // -------------------------------------------------------------------------------------------------------------
29 // ------------ # Code for extracting traffic generated by a device within x seconds of a trigger # ------------
30 // Paths to input and output files (consider supplying these as arguments instead)
31 final String inputPcapFile = "/Users/varmarken/temp/UCI IoT Project/June2018 experiments/tplink/tplink.wlan1.local.pcap";
32 final String outputPcapFile = "/Users/varmarken/temp/UCI IoT Project/June2018 experiments/tplink/tplink-filtered.pcap";
33 final String triggerTimesFile = "/Users/varmarken/temp/UCI IoT Project/June2018 experiments/tplink/tplink-june-14-2018-timestamps.txt";
34 // IP of the device for which traffic is to be extracted
35 final String deviceIp = "192.168.1.159";
37 TriggerTimesFileReader ttfr = new TriggerTimesFileReader();
38 List<Instant> triggerTimes = ttfr.readTriggerTimes(triggerTimesFile, false);
39 TriggerTrafficExtractor tte = new TriggerTrafficExtractor(inputPcapFile, triggerTimes, deviceIp);
40 final PcapDumper outputter = Pcaps.openDead(DataLinkType.EN10MB, 65536).dumpOpen(outputPcapFile);
41 DnsMap dnsMap = new DnsMap();
42 TcpReassembler tcpReassembler = new TcpReassembler();
43 tte.performExtraction(pkt -> {
46 } catch (NotOpenException e) {
49 }, dnsMap, tcpReassembler);
52 // -------------------------------------------------------------------------------------------------------------
53 // -------------------------------------------------------------------------------------------------------------
59 // TP-Link MAC 50:c7:bf:33:1f:09 and usually IP 192.168.1.159 (remember to verify per file)