sns_utils 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51164a9c017dc73fee16d4748e3a5f51f7216ea1
4
- data.tar.gz: 4fa3100cb93b679b09eb73d9c1d33faf8fd2ccfd
3
+ metadata.gz: 620632d0cf549c2f51495c8d91a64c89d6dfeb0f
4
+ data.tar.gz: 674efcd5281dc6202312988c95c74142978a00c0
5
5
  SHA512:
6
- metadata.gz: 76a58e05f379dc0dec284d1312b8f5f28f22a71ab6ac2006f782bcee6011989f051290840f4410fba6bdc8cb2eafbe9f8e0d4f23e4242051b54cc3bbc62331df
7
- data.tar.gz: b300921c8de9956fa5acb06ff3f14a00714f56fec867662b48eafdad5c2410cbd3d22198e02683abc5a60328d02a79047e09427d8d0d1b9bf1a2b64cc30c7404
6
+ metadata.gz: 8b5f6de14432d3ec5e97f753eee6cdf4f27e7b29fc89ac5fca1bef70018a76f875da696542bc263a5f2fb77f06a2e1c675c533e62ba8541fb68afcebbdaba366
7
+ data.tar.gz: bb79f4bc4ede80e832832acdf40447fdbc7c9fb28b8625cf268ce0b347dd87719fd70b5fa14a771cfb8f337cebc8e8420cf4ee8059b05f314fe67eb45c0c93ab
@@ -3,10 +3,11 @@ module SnsUtils
3
3
  attr_accessor :file, :options
4
4
  attr_accessor :ip_addrs, :ip_addrs_log, :mac_addrs, :mac_addrs_log
5
5
 
6
- IPV4_REGEX = ::SnsUtils::IPv4::REGEX
7
- IPV6_REGEX = ::SnsUtils::IPv6::REGEX
8
- MAC_REGEX = ::SnsUtils::MAC::REGEX
9
- IP_REGEX = / ((?: ^|\s|[a-zA-Z]) (?: #{IPV6_REGEX} | #{IPV4_REGEX} | #{MAC_REGEX})) /xi
6
+ IP_REGEX = /
7
+ #{::SnsUtils::IPv4::REGEX} |
8
+ #{::SnsUtils::IPv6::REGEX} |
9
+ #{::SnsUtils::MAC::REGEX}
10
+ /xi
10
11
 
11
12
  def initialize(argv)
12
13
  @file, @options = parse_options(argv)
@@ -25,12 +26,14 @@ module SnsUtils
25
26
 
26
27
  def extract_addresses
27
28
  File.open(file, 'r').each do |line|
28
- line.scan(IP_REGEX).each { |md| log_addr(md[0].to_s.strip!) }
29
+ line.scan(IP_REGEX).each do |ip|
30
+ log_addr(ip)
31
+ end
29
32
  end
30
33
  end
31
34
 
32
35
  def log_ip_addrs
33
- self.ip_addrs_log = ip_addrs.select { |_, count| count >= options.ip_threshold }.keys
36
+ self.ip_addrs_log = ip_addrs.select { |_, count| count >= options.ip_threshold }.keys
34
37
  write_file(::SnsUtils.ip_out_file, ip_addrs_log)
35
38
  end
36
39
 
@@ -57,6 +60,8 @@ module SnsUtils
57
60
  rescue IPAddr::InvalidAddressError => e
58
61
  mac_addrs[ip] ||= 0
59
62
  mac_addrs[ip] += 1
63
+ rescue IPAddr::AddressFamilyError => e
64
+ $stderr.puts(e.message)
60
65
  end
61
66
 
62
67
  def parse_options(argv)
@@ -1,3 +1,3 @@
1
1
  module SnsUtils
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,2 +1,8 @@
1
- # should match two ips 123.12.12.126-16-2013
1
+ # should match one ip 123.12.12.126-16-2013
2
+ # should match one ip 6-7-201123.12.12.127
3
+ # should match one ip 6-7-201123.12.12.128-16-2013
2
4
  # invalid but should match by truncating last '0' 192.168.1.500
5
+ # invalid but should match by truncating last '5' 192.168.1.555:80
6
+ # ipv4 with port number 192.168.1.51:8080
7
+ # ipv8 with port number # valid 2001:0000:1234:0000:0000:C1C0:ABCD:0876:8080
8
+ # multi-line xyz:1 ip 123.12.12.129-16-2013 2013-1xxxy&& 2001:0000:1234:0000:0000:C1C0:ABCD:0877:8080 9%%%#+ 192.168.1.565:80
@@ -15,7 +15,7 @@ describe SnsUtils::IpExtractor do
15
15
 
16
16
  it "finds valid entries" do
17
17
  ipex = SnsUtils::IpExtractor.new([file]).run
18
- ipex.ip_addrs.should have(92).entries
18
+ ipex.ip_addrs.should have(96).entries
19
19
  end
20
20
  end
21
21
 
@@ -102,3 +102,17 @@ describe SnsUtils::IpExtractor do
102
102
  end
103
103
  end
104
104
  end
105
+
106
+
107
+ describe "SnsUtils::IpExtractor" do
108
+ context "extracting edge cases" do
109
+ let(:file) { fixture_path("edge_cases.log") }
110
+
111
+ it "finds valid entries" do
112
+ ipex = SnsUtils::IpExtractor.new([file]).run
113
+
114
+ pp ipex.ip_addrs
115
+ ipex.ip_addrs.should have(10).entries
116
+ end
117
+ end
118
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sns_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sahglie
@@ -131,3 +131,4 @@ test_files:
131
131
  - spec/fixtures/thresholds.log
132
132
  - spec/sns_utils/ip_extractor_spec.rb
133
133
  - spec/spec_helper.rb
134
+ has_rdoc: