kismet-gpsxml 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8234d01b84c6db59e1bfb433860be76d4f7d2f8
4
- data.tar.gz: e7c8f45dd59b43f05f8dc6ea91b22ef8711a5540
3
+ metadata.gz: 795d35c2d0f134187651956ebcc02dac33b33f3c
4
+ data.tar.gz: 79cfb9f7bb72725ed648c586331857f959389018
5
5
  SHA512:
6
- metadata.gz: 79e2c8ea84b57a3a86552bf263ff7a3bc95449544cd7b6c5ea7f1a62301538bbabf0cea52d8f2fe37b7bb472795155beeef4c2d8c71bd95abaaa7cbf9ad91549
7
- data.tar.gz: ebada54bac827dc690e8c523e0bb52c49c3fdd8ee8a63d49524291b8694eb7c920e8af5e95642eedeb25bc7ffd0df28d2b2e2a611265579bcec316e7cda2961b
6
+ metadata.gz: 979750dcfbcf764301602085d894b86fa5bfe6b1b029a5d228a1cbdc79a939faa62af1dbb3099d9ccc4657059dc79ddb7d2ecad0a6bacaf26b0932800aafdaa1
7
+ data.tar.gz: 559e322a14e3ac870ac24e17f9043cddcd44757a3cd89dd0687519d96d334168d5101be77b400c735474889a9e7bc209d681b60568f77b43397e1b8e7bf78d00
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'kismet-gpsxml'
4
+
5
+ unless ARGV[0]
6
+ $stderr.puts "Usage: #{__FILE__} logfile.gpsxml > output.gpsxml"
7
+ exit 1
8
+ end
9
+
10
+ file = ARGV[0]
11
+
12
+ reader = Kismet::GPSXML::Reader.from_io File.open(file)
13
+
14
+ count = reader.write_interesting_nodes_to_file STDOUT
15
+
16
+ $stderr.puts "\n#{count} gps-point written."
data/bin/gpsxml2csv CHANGED
@@ -5,7 +5,9 @@ require 'kismet-gpsxml'
5
5
  DEFAULT_ROUNDING = 4
6
6
 
7
7
  unless ARGV[0]
8
- $stderr.puts "Usage: #{__FILE__} logfile.gpsxml [rounding-level]\nDefault rounding-level is #{DEFAULT_ROUNDING} decimal places."
8
+ $stderr.puts "Usage: #{__FILE__} logfile.gpsxml [rounding-level]"
9
+ $stderr.puts "Default rounding-level is #{DEFAULT_ROUNDING} decimal places."
10
+ $stderr.puts "Set GPSXML_OUTPUT_XML if you want the output to be XML."
9
11
  exit 1
10
12
  end
11
13
 
@@ -15,8 +17,20 @@ rounding = ARGV[1] ? ARGV[1].to_i : DEFAULT_ROUNDING
15
17
  reader = Kismet::GPSXML::Reader.from_io File.open(file)
16
18
  reader.rounding = rounding
17
19
 
18
- points = reader.points
20
+ bssids = reader.bssids_by_lat_long
19
21
 
20
- points.each do |point,set|
21
- puts [point, set.size].join(",")
22
+ unless ENV['GPSXML_OUTPUT_XML']
23
+ bssids.each do |point,set|
24
+ puts [point, set.size].join(",")
25
+ end
26
+ else
27
+ puts '<points input="%s" >' % File.basename(file)
28
+ bssids.each do |point,set|
29
+ puts '<point coord="%s" count="%d">' % [point, set.size]
30
+ set.each do |bssid|
31
+ puts '<bssid>%s</bssid>' % bssid
32
+ end
33
+ puts '</point>'
34
+ end
35
+ puts "</points>"
22
36
  end
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: kismet-gpsxml 0.1.1 ruby lib
5
+ # stub: kismet-gpsxml 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "kismet-gpsxml"
9
- s.version = "0.1.1"
9
+ s.version = "0.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.date = "2014-09-14"
15
15
  s.description = "A quick solution to model Kismet-generated gpsxml log files and output to CSV"
16
16
  s.email = "colin.dean@metamesh.org"
17
- s.executables = ["gpsxml2csv"]
17
+ s.executables = ["gpsxml-filter-bad-bssid", "gpsxml2csv"]
18
18
  s.extra_rdoc_files = [
19
19
  "LICENSE.txt",
20
20
  "README.md"
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "README.md",
28
28
  "Rakefile",
29
29
  "VERSION",
30
+ "bin/gpsxml-filter-bad-bssid",
30
31
  "bin/gpsxml2csv",
31
32
  "kismet-gpsxml.gemspec",
32
33
  "lib/kismet-gpsxml.rb",
data/lib/kismet-gpsxml.rb CHANGED
@@ -22,25 +22,73 @@ class Kismet::GPSXML::Reader
22
22
  @rounding = 4
23
23
  end
24
24
 
25
- def points
25
+ def bssids_by_lat_long
26
26
  points = {}
27
27
  reader.each do |node|
28
- next unless interesting_node? node
28
+ next unless interesting_gpsxml_node? node
29
29
  point = point_info node
30
30
  lat, lon, bssid = point.values
31
31
  key = [lat,lon].join(",")
32
- points[key] = Set.new if points[key].nil?
32
+ points[key] = SortedSet.new if points[key].nil?
33
33
  points[key].add bssid
34
34
  end
35
35
  points
36
36
  end
37
37
 
38
+ # Returns the number of interesting_gpsxml_nodes it wrote
39
+ def write_interesting_nodes_to_file io
40
+ counter = 0
41
+ reader.each do |node|
42
+ unless undesirable_node? node
43
+ io.write node_to_string(node)
44
+ counter += 1 if interesting_gpsxml_node? node
45
+ end
46
+ end
47
+ counter
48
+ end
49
+
38
50
  private
39
51
 
40
- def interesting_node? node
41
- node.name == "gps-point" &&
52
+ def is_gpspoint? node
42
53
  node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT &&
43
- node.attribute("bssid") != "00:00:00:00:00:00"
54
+ node.name == "gps-point"
55
+ end
56
+
57
+ def interesting_gpsxml_node? node
58
+ is_gpspoint?(node) &&
59
+ !undesirable_node?(node)
60
+ end
61
+
62
+ def undesirable_node? node
63
+ is_gpspoint?(node) &&
64
+ (
65
+ node.attribute("bssid") == "00:00:00:00:00:00" ||
66
+ node.attribute("bssid") == "GP:SD:TR:AC:KL:OG"
67
+ )
68
+ end
69
+
70
+ def node_to_string node
71
+ case node.node_type
72
+ when Nokogiri::XML::Reader::TYPE_ELEMENT
73
+ open_node_with_attrs(node)
74
+ when Nokogiri::XML::Reader::TYPE_END_ELEMENT
75
+ close_node(node)
76
+ when Nokogiri::XML::Reader::TYPE_DOCUMENT_TYPE
77
+ node.outer_xml
78
+ when Nokogiri::XML::Reader::TYPE_TEXT
79
+ node.value
80
+ end
81
+ end
82
+
83
+ def close_node node
84
+ "</"+node.name+">"
85
+ end
86
+
87
+ def open_node_with_attrs node
88
+ name = node.name
89
+ attrs = node.attributes.collect{|k,v| '%s="%s"'%[k,v] }.join(' ')
90
+ closing = node.self_closing? ? '/' : ''
91
+ "<#{[name,attrs].join(' ')}#{closing}>"
44
92
  end
45
93
 
46
94
  def point_info node
data/test/helper.rb CHANGED
@@ -34,3 +34,7 @@ require 'kismet-gpsxml'
34
34
  def test_xml_location
35
35
  File.join [File.dirname(__FILE__), "test.xml"]
36
36
  end
37
+
38
+ def test_write_location extra=""
39
+ File.join [File.dirname(__FILE__), "test_output#{extra}.xml"]
40
+ end
@@ -9,7 +9,7 @@ describe Kismet::GPSXML::Reader do
9
9
  end
10
10
 
11
11
  it "responds to points" do
12
- subject.public_instance_methods.must_include :points
12
+ subject.public_instance_methods.must_include :bssids_by_lat_long
13
13
  # subject.must_respond_to :points # this doesn't work on classes, just instances
14
14
  end
15
15
 
@@ -20,24 +20,50 @@ describe Kismet::GPSXML::Reader do
20
20
 
21
21
  describe "IO operations" do
22
22
  let(:text_xml_io) { File.open test_xml_location }
23
+ let(:text_write_io) { File.open test_write_location, 'w' }
24
+
23
25
 
24
26
  before do
25
27
  text_xml_io.rewind
26
28
  @reader = subject.from_io text_xml_io
27
29
  end
28
30
 
31
+ #after do
32
+ #puts "what %s" % passed?
33
+ #if passed?
34
+ # if File.exists?(text_write_io) || File.exists?(test_write_location)
35
+ # File.unlink test_write_location
36
+ # end
37
+ #end
38
+ #end
39
+
40
+
29
41
  it "retrieves points" do
30
- @reader.points.wont_be_empty
42
+ @reader.bssids_by_lat_long.wont_be_empty
31
43
  end
32
44
 
33
45
  it "retrieves the expected number of points" do
34
- @reader.points.size.must_equal 4 # one should be filtered out
46
+ @reader.bssids_by_lat_long.size.must_equal 4 # one should be filtered out
35
47
  end
36
48
 
37
49
  it "filters bssid = 00:00:00:00:00:00" do
38
- points_with_bad_bssid = @reader.points.select{|position,bssid| bssid == '00:00:00:00:00:00'}
50
+ points_with_bad_bssid = @reader.bssids_by_lat_long.select{|position,bssid| bssid == '00:00:00:00:00:00'}
39
51
  points_with_bad_bssid.must_be_empty
40
52
  end
41
53
 
54
+ it "writes the expected number of points" do
55
+ count = @reader.write_interesting_nodes_to_file text_write_io
56
+ text_write_io.close
57
+ count.must_equal 4
58
+ end
59
+
60
+ it "writes the expected number of points, then doesn't filter more" do
61
+ count1 = @reader.write_interesting_nodes_to_file text_write_io
62
+ text_write_io.close
63
+ @reader2 = subject.from_io File.open(test_write_location)
64
+ count2 = @reader2.write_interesting_nodes_to_file File.open(test_write_location("-second"), 'w')
65
+
66
+ count1.must_equal count2
67
+ end
42
68
  end
43
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kismet-gpsxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Dean
@@ -98,6 +98,7 @@ description: A quick solution to model Kismet-generated gpsxml log files and out
98
98
  to CSV
99
99
  email: colin.dean@metamesh.org
100
100
  executables:
101
+ - gpsxml-filter-bad-bssid
101
102
  - gpsxml2csv
102
103
  extensions: []
103
104
  extra_rdoc_files:
@@ -111,6 +112,7 @@ files:
111
112
  - README.md
112
113
  - Rakefile
113
114
  - VERSION
115
+ - bin/gpsxml-filter-bad-bssid
114
116
  - bin/gpsxml2csv
115
117
  - kismet-gpsxml.gemspec
116
118
  - lib/kismet-gpsxml.rb