http_scanner 0.1.0 → 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: 6ed1dbf8a0e517b5a1682938a33a0e84b55d54b9
4
- data.tar.gz: 81fbd0b8543f53eb6c2e6d0da2a3af517b3a6e4d
3
+ metadata.gz: 38f278a58f0907cadd481b05f6c545b31654f93a
4
+ data.tar.gz: 49f94ff59b7cee79b67d3e80d6649ee5ffe96989
5
5
  SHA512:
6
- metadata.gz: 8f22fd71e5e9d1ef5d4a2b3ac7376ef1ee8cc1e61ab81fd0fb878c014873e49dea8689fd421f39ec7e1dc9f7f043f9dd18f5e405a4ff84c8e54dc6728bcc1799
7
- data.tar.gz: f8316edf7a0140da260f47d50591a70bb62af8e5492d49e6e2389ae7579ee627cdc7776834e3d59cde81c6a4a5194439bfde4e6019b2e6f36e0f5daca401c18d
6
+ metadata.gz: a6e233b1db9146e3c91f89600c88e3f8f12d25feff9a31192e48f994fb337e08d64a4b0bf41d7a966d80654365db62e99c21079bd99ab51cac0b27c0592329f7
7
+ data.tar.gz: 4f90bf51584b31a1c694ae12a1a291d99a0496b2cd3c0b1eed113a3cc166019ac470ed8f0f4d8ab9c9ad149cd4850647885ea48fd2b3435ee4b250b1fcf198a7
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile.lock CHANGED
@@ -1,13 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- http_scanner (0.1.0)
4
+ http_scanner (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.2.5)
10
+ docile (1.1.5)
11
+ json (1.8.3)
10
12
  rake (10.4.2)
13
+ redcarpet (3.3.1)
11
14
  rspec (3.3.0)
12
15
  rspec-core (~> 3.3.0)
13
16
  rspec-expectations (~> 3.3.0)
@@ -21,6 +24,12 @@ GEM
21
24
  diff-lcs (>= 1.2.0, < 2.0)
22
25
  rspec-support (~> 3.3.0)
23
26
  rspec-support (3.3.0)
27
+ simplecov (0.11.2)
28
+ docile (~> 1.1.0)
29
+ json (~> 1.8)
30
+ simplecov-html (~> 0.10.0)
31
+ simplecov-html (0.10.0)
32
+ yard (0.8.7.6)
24
33
 
25
34
  PLATFORMS
26
35
  ruby
@@ -29,4 +38,10 @@ DEPENDENCIES
29
38
  bundler (~> 1.9)
30
39
  http_scanner!
31
40
  rake (~> 10.0)
41
+ redcarpet (~> 3.3)
32
42
  rspec (~> 3.3)
43
+ simplecov (~> 0.11.2)
44
+ yard (~> 0.8)
45
+
46
+ BUNDLED WITH
47
+ 1.11.2
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # HttpScanner
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/http_scanner`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/bsdavidson/http_scanner.svg?branch=master)](https://travis-ci.org/bsdavidson/http_scanner)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ A small Ruby gem that will scan your local network for running HTTP services and return an array IP addresses.
6
+
7
+ Documentation is [available on RubyDoc.info](http://www.rubydoc.info/github/bsdavidson/http_scanner/).
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,7 +24,12 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ ```ruby
28
+ require 'http_scanner'
29
+
30
+ scanner = HttpScanner.new
31
+ ip_addresses = scanner.scan('SomeText') # Look for pages containing SomeText
32
+ ```
26
33
 
27
34
  ## Development
28
35
 
@@ -32,7 +39,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
39
 
33
40
  ## Contributing
34
41
 
35
- 1. Fork it ( https://github.com/[my-github-username]/http_scanner/fork )
42
+ 1. Fork it ( https://github.com/bsdavidson/http_scanner/fork )
36
43
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
44
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
45
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1 +1,17 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ rescue LoadError
7
+ nil
8
+ end
9
+
10
+ begin
11
+ require 'yard'
12
+ YARD::Rake::YardocTask.new
13
+ rescue LoadError
14
+ nil
15
+ end
16
+
17
+ task default: :spec
data/http_scanner.gemspec CHANGED
@@ -19,6 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.9'
22
+ spec.add_development_dependency 'simplecov', '~> 0.11.2'
22
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'redcarpet', '~> 3.3'
23
25
  spec.add_development_dependency 'rspec', '~> 3.3'
26
+ spec.add_development_dependency 'yard', '~> 0.8'
24
27
  end
data/lib/http_scanner.rb CHANGED
@@ -1,26 +1,43 @@
1
- require 'pp'
2
- require 'socket'
3
1
  require 'ipaddr'
2
+ require 'logger'
4
3
  require 'net/http'
4
+ require 'socket'
5
5
 
6
6
  require 'http_scanner/version'
7
7
 
8
8
  class HttpScanner
9
+ attr_writer :logger
10
+
9
11
  def initialize
10
12
  @mutex = Mutex.new
11
- @results = []
12
13
  @queue = Queue.new
13
- @ip_range = current_ip_range
14
+ @results = []
15
+ end
16
+
17
+ def logger
18
+ @logger ||= Logger.new(STDERR).tap do |logger|
19
+ logger.progname = 'http_scanner'
20
+ end
14
21
  end
15
22
 
16
- def scan(signature)
17
- addresses = get_ip_range(@ip_range[:ip_start], @ip_range[:ip_end])
23
+ # Scans the local network and returns an array of IP addresses of systems that
24
+ # return text containing the signature.
25
+ #
26
+ # @param signature [String] Case sensitive string to be searched for in the
27
+ # HTML of scanned systems.
28
+ # @param opts [Hash] Additional options.
29
+ # @option opts [Fixnum] :threads Size of the thread pool to use to scan the
30
+ # local network. Defaults to 255 threads.
31
+ # @return [Array] IP addresses of systems with a positive match.
32
+ def scan(signature, opts = {})
33
+ ip_range = local_ip_range
34
+ addresses = get_ips_in_range(ip_range[:ip_start], ip_range[:ip_end])
18
35
  addresses.each do |address|
19
36
  @queue << address
20
37
  end
21
38
  threads = []
22
39
 
23
- 255.times do
40
+ (opts[:threads] || 255).times do
24
41
  threads << Thread.new do
25
42
  thread_results = scan_thread(@queue, signature)
26
43
  @mutex.synchronize do
@@ -33,7 +50,8 @@ class HttpScanner
33
50
  begin
34
51
  thread.join
35
52
  rescue => e
36
- p "Thread Join Error: #{e}"
53
+ logger.error "Caught error in thread:"
54
+ logger.error e
37
55
  end
38
56
  end
39
57
  @results
@@ -41,23 +59,20 @@ class HttpScanner
41
59
 
42
60
  protected
43
61
 
44
- def current_ip_range
62
+ def local_ip_range
45
63
  ip_local = local_ip
46
- p '#####################################'
47
- p '# #'
48
- p '#' + "YOUR IP: #{ip_local}".center(35) + '#'
49
- p '# #'
50
- p '#####################################'
51
64
  ip = ip_local.split('.')
52
- ip_start = "#{ip[0]}.#{ip[1]}.#{ip[2]}.0"
65
+ ip_start = "#{ip[0]}.#{ip[1]}.#{ip[2]}.1"
53
66
  ip_end = "#{ip[0]}.#{ip[1]}.#{ip[2]}.255"
67
+ logger.debug "Local IP address: #{ip_local}"
68
+ logger.debug "Local IP range: #{ip_start}...#{ip_end}"
54
69
  {
55
70
  ip_start: ip_start,
56
71
  ip_end: ip_end
57
72
  }
58
73
  end
59
74
 
60
- def get_ip_range(start_ip, end_ip)
75
+ def get_ips_in_range(start_ip, end_ip)
61
76
  start_ip = IPAddr.new(start_ip)
62
77
  end_ip = IPAddr.new(end_ip)
63
78
  (start_ip..end_ip).map(&:to_s)
@@ -79,6 +94,7 @@ class HttpScanner
79
94
  read_timeout: 2,
80
95
  open_timeout: 2)
81
96
  rescue
97
+ logger.debug('#{addr}: connection error')
82
98
  nil
83
99
  end
84
100
  if http
@@ -91,14 +107,12 @@ class HttpScanner
91
107
  nil
92
108
  end
93
109
  if body.include?(signature)
94
- print "!#{addr} "
110
+ logger.debug "#{addr}: string found"
95
111
  results << addr
96
112
  else
97
- print '*'
113
+ logger.debug "#{addr}: string not found"
98
114
  end
99
115
  http.finish
100
- else
101
- print '.'
102
116
  end
103
117
  end
104
118
  rescue ThreadError
@@ -1,3 +1,3 @@
1
1
  class HttpScanner
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_scanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Davidson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-18 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.11.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.11.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
82
  version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
55
97
  description:
56
98
  email:
57
99
  - bsdavidson@gmail.com
@@ -61,6 +103,8 @@ extra_rdoc_files: []
61
103
  files:
62
104
  - ".gitignore"
63
105
  - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - ".yardopts"
64
108
  - CODE_OF_CONDUCT.md
65
109
  - Gemfile
66
110
  - Gemfile.lock
@@ -92,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
136
  version: '0'
93
137
  requirements: []
94
138
  rubyforge_project:
95
- rubygems_version: 2.2.2
139
+ rubygems_version: 2.5.1
96
140
  signing_key:
97
141
  specification_version: 4
98
142
  summary: A small Ruby gem that will scan your local network for running HTTP services