SimplePortSniff 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/LICENSE +21 -0
- data/README.md +44 -0
- data/bin/simplePortSniff +9 -0
- data/features/simplePortSniff.feature +13 -0
- data/features/step_definitions/simplePortSniff_steps.rb +24 -0
- data/features/support/env.rb +4 -0
- data/lib/simplePortSniff/simpleportsniff.rb +61 -0
- data/lib/simpleportsniff.rb +2 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 51a3f87c3d129c424023e6955746e6ce2da18868
|
|
4
|
+
data.tar.gz: de160ca0bd168e743bf1143e55f3fec93aed05e0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ec377d309bd55f3243c79ad2be4a497317c4ce7b76ff6d3b3046b0092c6369a14213cb327d91f67d39bb62474732c33b509f6dfc1c1b015335203409e59f1fab
|
|
7
|
+
data.tar.gz: 1b5e45a3f8aca011c2dc1275ac112f55da3d3588e28ad8f4f7d445fba55017be963108e7456d42a58036e5c3d03cfcfb1578c8fefc86ddfeeca0971beb99fda4
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Nicholas Sardo
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
[](https://badge.fury.io/rb/PortSniff)
|
|
3
|
+
# SimplePortSniff
|
|
4
|
+
Native Ruby naive port sniffer
|
|
5
|
+
|
|
6
|
+
Input an IP and a range of ports as an array, and get back which of those ports are open or closed.
|
|
7
|
+
|
|
8
|
+
## To use as a gem
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
gem install PortSniff
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Then, in your source file:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
require 'SimplePortSniff'
|
|
18
|
+
|
|
19
|
+
ps = SimplePortSniff.new( 'google.com', [79,80,81] )
|
|
20
|
+
puts s.sniff()
|
|
21
|
+
```
|
|
22
|
+
RETURNS:
|
|
23
|
+
```
|
|
24
|
+
port 79 is closed
|
|
25
|
+
port 80 is open
|
|
26
|
+
port 81 is closed
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## To work with the source files:
|
|
31
|
+
|
|
32
|
+
### To Run:
|
|
33
|
+
```
|
|
34
|
+
cd into bin/ and type: ./simplePortSniff (the file is already chmod a+x)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### To Run Cucumber Tests:
|
|
38
|
+
(requires Cucumber be installed...)
|
|
39
|
+
```
|
|
40
|
+
cd into the root directory of this project:
|
|
41
|
+
ruby-port-sniff/
|
|
42
|
+
|
|
43
|
+
then type: cucumber
|
|
44
|
+
```
|
data/bin/simplePortSniff
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
Feature: Sniff a port
|
|
3
|
+
In order to sniff a port
|
|
4
|
+
As a user
|
|
5
|
+
I want to sniff some ports
|
|
6
|
+
|
|
7
|
+
Scenario:
|
|
8
|
+
Given ip and ports are
|
|
9
|
+
| ip | google.com |
|
|
10
|
+
| ports| [79,80,81] |
|
|
11
|
+
When I enter the ip
|
|
12
|
+
And I enter the ports
|
|
13
|
+
Then Then the result should be "port 79 is closed\nport 80 is open\nport 81 is closed"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
Given(/^ip and ports are$/) do |table|
|
|
4
|
+
# table is a Cucumber::MultilineArgument::DataTable
|
|
5
|
+
#puts table.raw
|
|
6
|
+
#puts table.raw[0][0]
|
|
7
|
+
#puts table.raw[0][1]
|
|
8
|
+
@table = table.raw
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
When(/^I enter the ip$/) do
|
|
12
|
+
@ip = @table[0][1].to_s
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
When(/^I enter the ports$/) do
|
|
16
|
+
#puts @table[1][1].class == String !!
|
|
17
|
+
@ports = eval(@table[1][1])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Then(/^Then the result should be "([^"]*)"$/) do |arg1|
|
|
21
|
+
@sps = Simpleportsniff.new(@ip.to_s, @ports )
|
|
22
|
+
rslt = @sps.sniff()
|
|
23
|
+
rslt == arg1
|
|
24
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'socket'
|
|
2
|
+
|
|
3
|
+
class SimplePortSniff
|
|
4
|
+
|
|
5
|
+
def initialize( ip, ports )
|
|
6
|
+
@ip = ip
|
|
7
|
+
@ports = ports
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# this function modified from original at: https://spin.atomicobject.com/2013/09/30/socket-connection-timeout-ruby/
|
|
11
|
+
def connect( host, port, timeout = 5 )
|
|
12
|
+
# Convert the passed host into structures the non-blocking calls
|
|
13
|
+
# can deal with
|
|
14
|
+
addr = Socket.getaddrinfo(host, nil )
|
|
15
|
+
sockaddr = Socket.pack_sockaddr_in( port, addr[0][3] )
|
|
16
|
+
|
|
17
|
+
Socket.new(Socket.const_get( addr[0][0]), Socket::SOCK_STREAM, 0 ).tap do |socket|
|
|
18
|
+
socket.setsockopt( Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 )
|
|
19
|
+
|
|
20
|
+
begin
|
|
21
|
+
# Initiate the socket connection in the background. If it doesn't fail
|
|
22
|
+
# immediatelyit will raise an IO::WaitWritable (Errno::EINPROGRESS)
|
|
23
|
+
# indicating the connection is in progress.
|
|
24
|
+
socket.connect_nonblock( sockaddr )
|
|
25
|
+
|
|
26
|
+
rescue IO::WaitWritable
|
|
27
|
+
# IO.select will block until the socket is writable or the timeout
|
|
28
|
+
# is exceeded - whichever comes first.
|
|
29
|
+
if IO.select( nil, [socket], nil, timeout )
|
|
30
|
+
begin
|
|
31
|
+
# Verify there is now a good connection
|
|
32
|
+
socket.connect_nonblock( sockaddr )
|
|
33
|
+
rescue Errno::EISCONN
|
|
34
|
+
# Good news everybody, the socket is connected!
|
|
35
|
+
return "port #{port} is open"
|
|
36
|
+
rescue
|
|
37
|
+
# An unexpected exception was raised - the connection is no good.
|
|
38
|
+
socket.close
|
|
39
|
+
return "port #{port} is closed"
|
|
40
|
+
#raise
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
# IO.select returns nil when the socket is not ready before timeout
|
|
44
|
+
# seconds have elapsed
|
|
45
|
+
socket.close
|
|
46
|
+
return "port #{port} is closed"
|
|
47
|
+
#raise "Connection timeout"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def sniff()
|
|
54
|
+
rtn = []
|
|
55
|
+
@ports.each do |item|
|
|
56
|
+
rtn.push( connect( @ip, item, 1 ) )
|
|
57
|
+
end
|
|
58
|
+
return rtn.join("\n")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: SimplePortSniff
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nicholas Sardo
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A simple, native, and naive, Ruby Port Sniffer that takes IP and Port
|
|
14
|
+
range as inputs
|
|
15
|
+
email: nsardo@aol.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- bin/simplePortSniff
|
|
23
|
+
- features/simplePortSniff.feature
|
|
24
|
+
- features/step_definitions/simplePortSniff_steps.rb
|
|
25
|
+
- features/support/env.rb
|
|
26
|
+
- lib/simplePortSniff/simpleportsniff.rb
|
|
27
|
+
- lib/simpleportsniff.rb
|
|
28
|
+
homepage: https://rubygems.org/gems/Simpleportsniff
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata: {}
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
requirements: []
|
|
47
|
+
rubyforge_project:
|
|
48
|
+
rubygems_version: 2.6.11
|
|
49
|
+
signing_key:
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: Basic native and naive Ruby Port Sniffer
|
|
52
|
+
test_files: []
|