-
Notifications
You must be signed in to change notification settings - Fork 7
/
hcx-to-wigle.sh
executable file
·42 lines (27 loc) · 1.38 KB
/
hcx-to-wigle.sh
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
#!/bin/bash
FILENAME="$1-wigle.csv"
TMPFILE=$(mktemp)
# Sanity Checks
if [[ "$1" == "" ]]; then
echo Usage: "$0 <pcapng file>"
exit
fi
# Check if hcxpcapngtool is installed
which hcxpcapngtool > /dev/null || { echo Error: hcxpcapngtool is not installed, you can get it from "https://github.com/ZerBea/hcxtools"; exit 1; }
# Check if input file is pcapng file
if [[ $(file "$1" | grep pcapng) == "" ]]; then
echo Error: "$1" is not a pcapng file.
fi
# Get hcxdumptool version
APPLICATION=$(hcxpcapngtool "$1" | grep application | awk 'BEGIN { FS = " " } ; { print $2 }')
VERSION=$(hcxpcapngtool "$1" | grep application | awk 'BEGIN { FS = " " } ; { print $3 }')
VENDOR=$(hcxpcapngtool "$1" | grep "interface vendor" | awk 'BEGIN { FS = " " } ; {print $3 }')
# Create .csv from hcxpcapngtool
hcxpcapngtool "$1" --csv "$TMPFILE" > /dev/null
# Insert pre-header
echo "WigleWifi-1.4,appRelease=$APPLICATION $VERSION,model=$APPLICATION,release=$VERSION,device=$APPLICATION,display=$APPLICATION,board=$APPLICATION,brand=$VENDOR" > "$FILENAME"
# Insert header
echo "MAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type" >> "$FILENAME"
# Insert values from actual csv
awk 'BEGIN { FS = "\t" } ; $12=="S" {$15=-$15} $14=="W" {$16=-$16} { print $3","$4","$5$6","$1" "$2","$9","$10","$15","$16","$20",0,WIFI" }' "$TMPFILE" >> "$FILENAME"
rm "$TMPFILE"