portscanner 1.0.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 +7 -0
- data/bin/portscanner +15 -0
- data/lib/portscanner.rb +42 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 518d9c2bc8ec3081741b3a607ab961a2d86bd2eb
|
|
4
|
+
data.tar.gz: 3210cda4b869af40199f6cb054def0b46aba819d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ab8b3993f7562b936136161cbd572233aa4de86e73c147cab8bd90ef271a4caaf327fa6f555ccc678b25e488a963945e794a5b6868aa880afe3ddfcd4e02e447
|
|
7
|
+
data.tar.gz: 72f10ffcf6cd72c80863dc3ca48a2284700ff7967063808db702ccacfc8aa37945ba8e8a2833f6ef848930b173a7f8e2898f16043f785f51373c906f5ad1f4da
|
data/bin/portscanner
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'portscanner'
|
|
3
|
+
|
|
4
|
+
skaner = Scanner.new
|
|
5
|
+
|
|
6
|
+
if ARGV.empty? || ARGV.length == 1
|
|
7
|
+
puts "Usage: portscanner HOST PORT [PORT]"
|
|
8
|
+
puts "Host and at least one port is required"
|
|
9
|
+
exit(2)
|
|
10
|
+
else
|
|
11
|
+
puts "Scanning..."
|
|
12
|
+
skaner.run(ARGV[0], ARGV[1], ARGV[2])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
data/lib/portscanner.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'socket'
|
|
2
|
+
|
|
3
|
+
class Scanner
|
|
4
|
+
attr_reader :log
|
|
5
|
+
def initialize
|
|
6
|
+
@opened = []
|
|
7
|
+
@closed = []
|
|
8
|
+
@log = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def port_open?(host, port)
|
|
12
|
+
Socket.tcp(host, port, connect_timeout: 1) do |socket|
|
|
13
|
+
@opened << port
|
|
14
|
+
socket.close
|
|
15
|
+
end
|
|
16
|
+
rescue => error
|
|
17
|
+
@log << error.message
|
|
18
|
+
@closed << port
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def run(host, p_start, p_end)
|
|
22
|
+
if p_end
|
|
23
|
+
multi(host, p_start.to_i, p_end.to_i)
|
|
24
|
+
else
|
|
25
|
+
port_open?(host, p_start.to_i)
|
|
26
|
+
end
|
|
27
|
+
status
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def multi(host, p_start, p_end)
|
|
31
|
+
while p_start <= p_end do
|
|
32
|
+
Thread.new { port_open?(host, p_start) }.join
|
|
33
|
+
p_start += 1
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def status
|
|
38
|
+
puts "Opened: #{@opened.join(', ')}" if @opened.length > 0
|
|
39
|
+
puts "Closed: #{@closed.join(', ')}" if @closed.length > 0
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: portscanner
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- drunkdrop
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email: drunkdrop@users.noreply.github.com
|
|
15
|
+
executables:
|
|
16
|
+
- portscanner
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/portscanner
|
|
21
|
+
- lib/portscanner.rb
|
|
22
|
+
homepage:
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata: {}
|
|
26
|
+
post_install_message:
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
requirements: []
|
|
41
|
+
rubyforge_project:
|
|
42
|
+
rubygems_version: 2.5.1
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: Simple port scanner gem.
|
|
46
|
+
test_files: []
|