Kismet / Maemo Mapper merge script

This is a bit of a specialised one: I have a Nokia N800 - on which I run Maemo Mapper - (now known as 'Mappero') - using a Bluetooth GPS unit. This produces a track file in GPX format, which is an XML file with GPS points, segments, altitude and time. I sometimes run the Kismet wireless sniffer on another host, but this does not have GPS capability, and cannot connect with the N800 (it's a Zaurus SL-C860 with a Wi-Fi card, and no other way to communicate with other hosts - apart from IrDA, but the N800 doesn't have it).

I needed a way to combine the Zaurus' Kismet log with the track log on the N800, so I could see where I was when Kismet picked up a certain network (no reason, other than curiosity).

I wrote a script (debug statements removed) to perform this task. It's horrible, untidy and it probably has many bugs. It is slow and it gets slower, the longer it runs. It could be coded better in C, but my knowledge of C is abysmal. I wrote this as a quick hack and it does what it's supposed to.

As usual with my projects, this comes with no guarantee of success, and you run this at your own risk.

The script

#!/bin/bash

# Kismet network file / Maemo Mapper track file merge script
# Lex, 02-Nov-13

TRACK_FILE="${TRACK:-test.track}"
NETWORK_FILE="${NETWORK:-kismet.network}"

function debug()
{
  return 0
  # echo -e "Debug: $@"
}

function output()
{
  echo -e "${@}"
}

function lookup_pos()
{
  nn="${1}"
  t="${2: -14:8}"
  debug "lookup_pos: network name = ${nn}, input time = '${t}'"
  h="${t::2}"
  m="${t:3:2}"
  s="${t:6:2}"
  debug "Hours: ${h}\tMinutes: ${m}\tSeconds: ${s}"
  ts=$((10#${h}*3600+10#${m}*60+10#${s}))
  debug " (${ts} seconds)"
  q=0
  while read tf; do
   if [ "${q}" -eq 0 ]; then
    if [ "${tf::6}" = "<trkpt" ]; then
      eval ${tf:7:15}
      eval ${tf:23:15}
      debug "Lat: ${lat}\tLon: ${lon}"
    fi
    if [ "${tf::6}" = "<time>" ]; then
      debug "Time tag found: ${tf}"
      tm=${tf:17:8}
      debug "$tm"
      hb="${tm::2}"
      mb="${tm:3:2}"
      sb="${tm:6:2}"
      debug "Hours: ${hb}\tMinutes: ${mb}\tSeconds: ${sb}"
      tb=$((10#${hb}*3600+10#${mb}*60+10#${sb}))
      debug " (${tb} seconds)"
      if [ "${tb}" -gt "${ts}" ]; then
        debug "Time > lookup time (${tb} > ${ts})"
	debug "Last-seen pos = ${lat}N ${lon}E"
	output "Network: ${nn}"
	output "Min Loc: Lat ${lat} Lon ${lon} Alt 0.000000 Spd 0.000000\n"
	q=1
      fi
      debug "End of loop: q=${q}\n"
      # sleep 1
    fi
   fi
  done < ${TRACK_FILE}
  return 0
}

while read a; do
  debug "${a}"
  if [ "${a::7}" = "Network" ]; then
    nn="$(echo ${a} | cut -d "\"" -f 2)"
    output ">> Network name: ${nn}"
    while read b; do
      if [ "${b::5}" = "First" ]; then
        t="${b:13}"
	output "\033[2mTime: \033[32m${t}\033[m"
	lookup_pos "${nn}" "${t}"
	break
      fi
    done
  fi
done < ${NETWORK_FILE}

An output example

ESSIDs have been changed to protect identity, and GPS co-ordinates obfuscated.
>> Network name: BTHomeHub-8021
Time: "Sat Nov  2 15:55:22 2013"
Min Loc: Lat 51.108412 Lon -4.113241 Alt 0.000000 Spd 0.000000

>> Network name: Gadgets
Time: "Sat Nov  2 15:55:22 2013"
Min Loc: Lat 51.108438 Lon -4.113251 Alt 0.000000 Spd 0.000000

>> Network name: BTOpenzone
Time: "Sat Nov  2 15:55:22 2013"
Min Loc: Lat 51.108473 Lon -4.113253 Alt 0.000000 Spd 0.000000

>> Network name: BTHub3-ED9P
Time: "Sat Nov  2 15:55:22 2013"
Min Loc: Lat 51.108482 Lon -4.113253 Alt 0.000000 Spd 0.000000

>> Network name: Feepfeep
Time: "Sat Nov  2 15:55:23 2013"
Min Loc: Lat 51.108487 Lon -4.113255 Alt 0.000000 Spd 0.000000

>> Network name: SKYCA02A
Time: "Sat Nov  2 15:55:24 2013"
Min Loc: Lat 51.108493 Lon -4.113379 Alt 0.000000 Spd 0.000000

Issues

Suggested improvements

  1. Scan the files once and match times with GPS, and network names/times for the second file. Search the GPS file, keying on the time field.
  2. Rewrite it in C.
  3. Rewrite it in Python.

Thanks

Thank you to the author of Maemo Mapper, which is a rock-solid GPS app which I have used for many years. Thanks also to the author of Kismet - an application which I have found invaluable for network debugging, as well as general messing-about with wireless stuff.

Comments

Please send any comments to the email address on the contact page.
Return to the projects index page
Site index page