http_scanner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ed1dbf8a0e517b5a1682938a33a0e84b55d54b9
4
+ data.tar.gz: 81fbd0b8543f53eb6c2e6d0da2a3af517b3a6e4d
5
+ SHA512:
6
+ metadata.gz: 8f22fd71e5e9d1ef5d4a2b3ac7376ef1ee8cc1e61ab81fd0fb878c014873e49dea8689fd421f39ec7e1dc9f7f043f9dd18f5e405a4ff84c8e54dc6728bcc1799
7
+ data.tar.gz: f8316edf7a0140da260f47d50591a70bb62af8e5492d49e6e2389ae7579ee627cdc7776834e3d59cde81c6a4a5194439bfde4e6019b2e6f36e0f5daca401c18d
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+ .DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,32 @@
1
+ AllCops:
2
+ Include:
3
+ - Gemfile
4
+ - Guardfile
5
+ - Rakefile
6
+ - config.ru
7
+ - '**/*.rb'
8
+ Exclude:
9
+ - ignore/**/*
10
+ - node_modules/**/*
11
+ Metrics/AbcSize:
12
+ Enabled: no
13
+ Metrics/CyclomaticComplexity:
14
+ Enabled: no
15
+ Metrics/MethodLength:
16
+ Enabled: no
17
+ Metrics/PerceivedComplexity:
18
+ Enabled: no
19
+ Style/CaseIndentation:
20
+ Enabled: no
21
+ Style/Documentation:
22
+ Enabled: no
23
+ Style/GuardClause:
24
+ Enabled: no
25
+ Style/LineEndConcatenation:
26
+ Enabled: no
27
+ Style/RegexpLiteral:
28
+ Enabled: no
29
+ Style/RedundantSelf:
30
+ Enabled: no
31
+ Style/SpaceInsideHashLiteralBraces:
32
+ Enabled: no
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in http_scanner.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ http_scanner (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.3.0)
12
+ rspec-core (~> 3.3.0)
13
+ rspec-expectations (~> 3.3.0)
14
+ rspec-mocks (~> 3.3.0)
15
+ rspec-core (3.3.1)
16
+ rspec-support (~> 3.3.0)
17
+ rspec-expectations (3.3.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.3.0)
20
+ rspec-mocks (3.3.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.3.0)
23
+ rspec-support (3.3.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.9)
30
+ http_scanner!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.3)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Brian Davidson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # HttpScanner
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.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'http_scanner'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install http_scanner
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/http_scanner/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'http_scanner'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'http_scanner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'http_scanner'
8
+ spec.version = HttpScanner::VERSION
9
+ spec.authors = ['Brian Davidson']
10
+ spec.email = ['bsdavidson@gmail.com']
11
+
12
+ spec.summary = %q{A small Ruby gem that will scan your local network for running HTTP services and return an array IP addresses.}
13
+ spec.homepage = 'https://github.com/bsdavidson/http_scanner'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.9'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.3'
24
+ end
@@ -0,0 +1,3 @@
1
+ class HttpScanner
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,108 @@
1
+ require 'pp'
2
+ require 'socket'
3
+ require 'ipaddr'
4
+ require 'net/http'
5
+
6
+ require 'http_scanner/version'
7
+
8
+ class HttpScanner
9
+ def initialize
10
+ @mutex = Mutex.new
11
+ @results = []
12
+ @queue = Queue.new
13
+ @ip_range = current_ip_range
14
+ end
15
+
16
+ def scan(signature)
17
+ addresses = get_ip_range(@ip_range[:ip_start], @ip_range[:ip_end])
18
+ addresses.each do |address|
19
+ @queue << address
20
+ end
21
+ threads = []
22
+
23
+ 255.times do
24
+ threads << Thread.new do
25
+ thread_results = scan_thread(@queue, signature)
26
+ @mutex.synchronize do
27
+ @results.concat(thread_results)
28
+ end
29
+ end
30
+ end
31
+
32
+ threads.each do |thread|
33
+ begin
34
+ thread.join
35
+ rescue => e
36
+ p "Thread Join Error: #{e}"
37
+ end
38
+ end
39
+ @results
40
+ end
41
+
42
+ protected
43
+
44
+ def current_ip_range
45
+ ip_local = local_ip
46
+ p '#####################################'
47
+ p '# #'
48
+ p '#' + "YOUR IP: #{ip_local}".center(35) + '#'
49
+ p '# #'
50
+ p '#####################################'
51
+ ip = ip_local.split('.')
52
+ ip_start = "#{ip[0]}.#{ip[1]}.#{ip[2]}.0"
53
+ ip_end = "#{ip[0]}.#{ip[1]}.#{ip[2]}.255"
54
+ {
55
+ ip_start: ip_start,
56
+ ip_end: ip_end
57
+ }
58
+ end
59
+
60
+ def get_ip_range(start_ip, end_ip)
61
+ start_ip = IPAddr.new(start_ip)
62
+ end_ip = IPAddr.new(end_ip)
63
+ (start_ip..end_ip).map(&:to_s)
64
+ end
65
+
66
+ def local_ip
67
+ ip = Socket.ip_address_list.detect(&:ipv4_private?)
68
+ ip.ip_address if ip
69
+ end
70
+
71
+ def scan_thread(queue, signature)
72
+ results = []
73
+
74
+ loop do
75
+ addr = queue.pop(true)
76
+ uri = URI.parse("http://#{addr}/")
77
+ http = begin
78
+ Net::HTTP.start(uri.host, uri.port,
79
+ read_timeout: 2,
80
+ open_timeout: 2)
81
+ rescue
82
+ nil
83
+ end
84
+ if http
85
+ body = ''
86
+ begin
87
+ http.get('/') do |chunk|
88
+ body += chunk
89
+ end
90
+ rescue
91
+ nil
92
+ end
93
+ if body.include?(signature)
94
+ print "!#{addr} "
95
+ results << addr
96
+ else
97
+ print '*'
98
+ end
99
+ http.finish
100
+ else
101
+ print '.'
102
+ end
103
+ end
104
+ rescue ThreadError
105
+ results = results.uniq
106
+ results
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: http_scanner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Davidson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ description:
56
+ email:
57
+ - bsdavidson@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - http_scanner.gemspec
73
+ - lib/http_scanner.rb
74
+ - lib/http_scanner/version.rb
75
+ homepage: https://github.com/bsdavidson/http_scanner
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A small Ruby gem that will scan your local network for running HTTP services
99
+ and return an array IP addresses.
100
+ test_files: []
101
+ has_rdoc: