Skip to content

Instantly share code, notes, and snippets.

@obihann
Last active August 28, 2018 21:39
Show Gist options
  • Select an option

  • Save obihann/891d224231b52c93d94ab4d1e5c952c3 to your computer and use it in GitHub Desktop.

Select an option

Save obihann/891d224231b52c93d94ab4d1e5c952c3 to your computer and use it in GitHub Desktop.
Log ESSIDs
#!/bin/sh -e
_WLAN=$1
_DATE=$(date +%Y%m%d)
_STAMP=$(date +%s)
_LOG_DIR=/var/log/essids
_TMP=/tmp/essids.tmp
_LOG=$_LOG_DIR/$_DATE/$_STAMP.log
_OPEN=$_LOG_DIR/$_DATE/$_STAMP-open.log
_CLOSED=$_LOG_DIR/$_DATE/$_STAMP-closed.log
_CLOSED_ALL=$_LOG_DIR/closed.log
_OPEN_ALL=$_LOG_DIR/open.log
_ALL=$_LOG_DIR/all.log
mkdir -p "$_LOG_DIR"/"$_DATE"
if [ $# -eq 0 ]
then
_WLAN=wlan0
fi
strip_logs() {
grep -B4 "Encryption key:$1" "$_TMP" | \
awk -F 'ESSID:"' '{print $2}' | \
sed -e '/^\s*$/d' -e 's/"$//' > "$2"
cat "$2" >> "$3"
sort -u "$3" -o "$3"
sed -i -e '/<hidden>/d' "$3"
}
/sbin/iwlist "$_WLAN" scan > "$_TMP"
strip_logs 'on' "$_CLOSED" "$_CLOSED_ALL"
strip_logs 'off' "$_OPEN" "$_OPEN_ALL"
sort "$_OPEN" "$_CLOSED" -o "$_LOG"
sort "$_OPEN_ALL" "$_CLOSED_ALL" -o "$_ALL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment