| 1 |
// License: BSD/LGPL |
| 2 |
// Copyright (C) 2011-2018 Thomas d'Otreppe |
| 3 |
using System; |
| 4 |
|
| 5 |
namespace WirelessPanda.Readers |
| 6 |
{ |
| 7 |
public class KismetCsvReader : Reader |
| 8 |
{ |
| 9 |
/// <summary> |
| 10 |
/// Date format (Same format for Kismet CSV and NetXML) |
| 11 |
/// </summary> |
| 12 |
protected override string DATE_FORMAT |
| 13 |
{ |
| 14 |
get |
| 15 |
{ |
| 16 |
return "ddd MMM dd HH:mm:ss yyyy"; |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
/// <summary> |
| 21 |
/// Date format (Same format for Kismet CSV and NetXML) |
| 22 |
/// </summary> |
| 23 |
protected override string ALT_DATE_FORMAT |
| 24 |
{ |
| 25 |
get |
| 26 |
{ |
| 27 |
return "ddd MMM d HH:mm:ss yyyy"; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
/// <summary> |
| 33 |
/// Reader type |
| 34 |
/// </summary> |
| 35 |
public override string ReaderType |
| 36 |
{ |
| 37 |
get |
| 38 |
{ |
| 39 |
return "Kismet CSV"; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
/// <summary> |
| 44 |
/// Constructor |
| 45 |
/// </summary> |
| 46 |
/// <param name="filename">Filename (doesn't need to exist now but MUST when using Read() )</param> |
| 47 |
public KismetCsvReader(string filename) : base(filename) { } |
| 48 |
|
| 49 |
/// <summary> |
| 50 |
/// Read/Update the content of the file |
| 51 |
/// </summary> |
| 52 |
/// <returns>true if successful</returns> |
| 53 |
/// <exception cref="FormatException">Airodump-ng CSV format unknown</exception> |
| 54 |
public override bool Read() |
| 55 |
{ |
| 56 |
// Reset parsing status |
| 57 |
this.ParseSuccess = false; |
| 58 |
|
| 59 |
// Get the content of the file |
| 60 |
string[] content = this.getStrippedFileContent(); |
| 61 |
|
| 62 |
// Check if this is really a kismet CSV file |
| 63 |
if (content.Length == 0) |
| 64 |
{ |
| 65 |
throw new FormatException("Empty file"); |
| 66 |
} |
| 67 |
|
| 68 |
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;"); |
| 69 |
if (!this.ParseSuccess) |
| 70 |
{ |
| 71 |
throw new FormatException("Not a Kismet CSV file"); |
| 72 |
} |
| 73 |
|
| 74 |
// Parse content |
| 75 |
for (int i = 1; i < content.Length && !string.IsNullOrEmpty(content[i]); i++) |
| 76 |
{ |
| 77 |
string [] split = content[i].Split(';'); |
| 78 |
|
| 79 |
// Check if there are enough elements |
| 80 |
if (split.Length < 39) |
| 81 |
{ |
| 82 |
continue; |
| 83 |
} |
| 84 |
|
| 85 |
AccessPoint ap = new AccessPoint(); |
| 86 |
|
| 87 |
// Skip first element which is the network number (if someone cares about it, email me) |
| 88 |
ap.NetworkType = split[1].Trim(); |
| 89 |
ap.ESSID = split[2].Trim(); |
| 90 |
ap.ESSIDLength = (byte)split[2].Length; |
| 91 |
ap.BSSID = split[3].Trim(); |
| 92 |
ap.Info = split[4].Trim(); |
| 93 |
ap.Channel = int.Parse(split[5]); |
| 94 |
ap.Cloaked = (split[6].Trim().ToLower() == "yes"); |
| 95 |
ap.Encryption = split[7].Trim(); |
| 96 |
ap.Decrypted = (split[8].Trim().ToLower() == "yes"); |
| 97 |
ap.MaxRate = double.Parse(split[9]); |
| 98 |
ap.MaxSeenRate = double.Parse(split[10]); |
| 99 |
ap.Beacon = ulong.Parse(split[11]); |
| 100 |
ap.LLC = ulong.Parse(split[12]); |
| 101 |
ap.DataFrames = ulong.Parse(split[13]); |
| 102 |
ap.Crypt = ulong.Parse(split[14]); |
| 103 |
ap.Weak = ulong.Parse(split[15]); |
| 104 |
ap.Total = ulong.Parse(split[16]); |
| 105 |
ap.Carrier = split[17].Trim(); |
| 106 |
ap.Encoding = split[18].Trim(); |
| 107 |
ap.FirstTimeSeen = this.parseDateTime(split[19]); |
| 108 |
ap.LastTimeSeen = this.parseDateTime(split[20]); |
| 109 |
ap.BestQuality = int.Parse(split[21]); |
| 110 |
ap.BestSignal = int.Parse(split[22]); |
| 111 |
ap.BestNoise = int.Parse(split[23]); |
| 112 |
ap.MinLocation = new Coordinates(split[24], split[25], split[26], split[27]); |
| 113 |
ap.MaxLocation = new Coordinates(split[28], split[29], split[30], split[31]); |
| 114 |
ap.BestLocation = new Coordinates(split[32], split[33], split[34], ""); |
| 115 |
ap.DataSize = ulong.Parse(split[35]); |
| 116 |
ap.IPType = int.Parse(split[36]); |
| 117 |
ap.IP = split[37].Replace(" ", ""); |
| 118 |
|
| 119 |
this.addAccessPoint(ap); |
| 120 |
} |
| 121 |
|
| 122 |
// No need to link stations and access points together since there are only access points. |
| 123 |
|
| 124 |
return true; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
} |
| 129 |
} |