File: kismetCsvReader.cs

package info (click to toggle)
aircrack-ng 1%3A1.5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 17,416 kB
  • sloc: ansic: 67,243; cs: 5,392; python: 2,619; sh: 2,102; makefile: 1,001; asm: 569; cpp: 69
file content (129 lines) | stat: -rw-r--r-- 5,020 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// License: BSD/LGPL
// Copyright (C) 2011-2018 Thomas d'Otreppe
using System;

namespace WirelessPanda.Readers
{
    public class KismetCsvReader : Reader
    {
        /// <summary>
        /// Date format (Same format for Kismet CSV and NetXML)
        /// </summary>
        protected override string DATE_FORMAT
        {
            get
            {
                return "ddd MMM dd HH:mm:ss yyyy";
            }
        }

        /// <summary>
        /// Date format (Same format for Kismet CSV and NetXML)
        /// </summary>
        protected override string ALT_DATE_FORMAT
        {
            get
            {
                return "ddd MMM  d HH:mm:ss yyyy";
            }
        }


        /// <summary>
        /// Reader type
        /// </summary>
        public override string ReaderType
        {
            get
            {
                return "Kismet CSV";
            }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="filename">Filename (doesn't need to exist now but MUST when using Read() )</param>
        public KismetCsvReader(string filename) : base(filename) { }

        /// <summary>
        /// Read/Update the content of the file
        /// </summary>
        /// <returns>true if successful</returns>
        /// <exception cref="FormatException">Airodump-ng CSV format unknown</exception>
        public override bool Read()
        {
            // Reset parsing status
            this.ParseSuccess = false;

            // Get the content of the file
            string[] content = this.getStrippedFileContent();

            // Check if this is really a kismet CSV file
            if (content.Length == 0)
            {
                throw new FormatException("Empty file");
            }

            this.ParseSuccess = (content[0] == "Network;NetType;ESSID;BSSID;Info;Channel;Cloaked;Encryption;Decrypted;MaxRate;MaxSeenRate;Beacon;LLC;Data;Crypt;Weak;Total;Carrier;Encoding;FirstTime;LastTime;BestQuality;BestSignal;BestNoise;GPSMinLat;GPSMinLon;GPSMinAlt;GPSMinSpd;GPSMaxLat;GPSMaxLon;GPSMaxAlt;GPSMaxSpd;GPSBestLat;GPSBestLon;GPSBestAlt;DataSize;IPType;IP;");
            if (!this.ParseSuccess)
            {
                throw new FormatException("Not a Kismet CSV file");
            }

            // Parse content
            for (int i = 1; i < content.Length && !string.IsNullOrEmpty(content[i]); i++)
            {
                string [] splitted = content[i].Split(';');

                // Check if there are enough elements
                if (splitted.Length < 39)
                {
                    continue;
                }

                AccessPoint ap = new AccessPoint();
                
                // Skip first element which is the network number (if someone cares about it, email me)
                ap.NetworkType = splitted[1].Trim();
                ap.ESSID = splitted[2].Trim();
                ap.ESSIDLength = (byte)splitted[2].Length;
                ap.BSSID = splitted[3].Trim();
                ap.Info = splitted[4].Trim();
                ap.Channel = int.Parse(splitted[5]);
                ap.Cloaked = (splitted[6].Trim().ToLower() == "yes");
                ap.Encryption = splitted[7].Trim();
                ap.Decrypted = (splitted[8].Trim().ToLower() == "yes");
                ap.MaxRate = double.Parse(splitted[9]);
                ap.MaxSeenRate = double.Parse(splitted[10]);
                ap.Beacon = ulong.Parse(splitted[11]);
                ap.LLC = ulong.Parse(splitted[12]);
                ap.DataFrames = ulong.Parse(splitted[13]);
                ap.Crypt = ulong.Parse(splitted[14]);
                ap.Weak = ulong.Parse(splitted[15]);
                ap.Total = ulong.Parse(splitted[16]);
                ap.Carrier = splitted[17].Trim();
                ap.Encoding = splitted[18].Trim();
                ap.FirstTimeSeen = this.parseDateTime(splitted[19]);
                ap.LastTimeSeen = this.parseDateTime(splitted[20]);
                ap.BestQuality = int.Parse(splitted[21]);
                ap.BestSignal = int.Parse(splitted[22]);
                ap.BestNoise = int.Parse(splitted[23]);
                ap.MinLocation = new Coordinates(splitted[24], splitted[25], splitted[26], splitted[27]);
                ap.MaxLocation = new Coordinates(splitted[28], splitted[29], splitted[30], splitted[31]);
                ap.BestLocation = new Coordinates(splitted[32], splitted[33], splitted[34], "");
                ap.DataSize = ulong.Parse(splitted[35]);
                ap.IPType = int.Parse(splitted[36]);
                ap.IP = splitted[37].Replace(" ", "");

                this.addAccessPoint(ap);
            }

            // No need to link stations and access points together since there are only access points.

            return true;
        }

        
    }
}