thecon 0.0.2
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/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/thecon/version.rb +3 -0
- data/lib/thecon.rb +44 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/thecon_spec.rb +23 -0
- data/thecon.gemspec +22 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 190b3edb3ccf2f8fb1485a42f49f0aaebfda606f
|
4
|
+
data.tar.gz: ce6b74d3d88f0135db81c327c1dd6d592d61cfbe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b935ddea4a3e3263ca2a26ba8a127e1eb8bc544e2d59cb1855f6c9b7f8eaf1e919c92751ec23e3c6ee68faca0d464c038fabaa7e42722ae4ebc4edef899b9e4
|
7
|
+
data.tar.gz: e3e7a71ae5e1ad270dfbab0ba39de1b5f4c578b7a6052c6956e8a509ca496b00810301f57f4b7cf52d530f26d386dec1c8b47f4c9ca181e976de62402b81d17e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
thecon
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 tnarik
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Thecon
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'thecon'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install thecon
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/thecon.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "thecon/version"
|
2
|
+
|
3
|
+
require 'timeout'
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
module Thecon
|
7
|
+
# Your code goes here...
|
8
|
+
def self.ready?(port=80, ip = "localhost", connection_timeout = 3, read_timeout = 2)
|
9
|
+
result = false
|
10
|
+
begin
|
11
|
+
timeout( connection_timeout ) do
|
12
|
+
socket = Socket.new :INET, :STREAM
|
13
|
+
sockaddr = Socket.pack_sockaddr_in port, ip
|
14
|
+
socket.connect sockaddr
|
15
|
+
begin
|
16
|
+
timeout( read_timeout ) do
|
17
|
+
r,w,e = select([socket], nil, nil, 1) # nil, nil, nil from inside the network
|
18
|
+
unless r.nil? then
|
19
|
+
p "socket was closed" if ( r[0].read(1).nil? ) #This means there is something there
|
20
|
+
result = false #Something closed this
|
21
|
+
else
|
22
|
+
p "not available for read: either doesn't exist or not closed" #TRUE
|
23
|
+
result = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue StandardError => ka
|
27
|
+
p "OK, standardERROR #{ka}" #If socket.read there could be errors (this shouldn't be triggered)
|
28
|
+
result = true
|
29
|
+
rescue Timeout::Error => e
|
30
|
+
p "timedout reading" #Socket is there but there are not data to read (if socket.read)
|
31
|
+
result = true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
35
|
+
result=false # Connection fails on its own
|
36
|
+
rescue Timeout::Error, StandardError => e
|
37
|
+
result=false # When host or port is wrong (connection timesout or some other Errno)
|
38
|
+
rescue
|
39
|
+
end
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'thecon'
|
data/spec/thecon_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Thecon do
|
4
|
+
describe "::VERSION" do
|
5
|
+
it "exists" do
|
6
|
+
expect(Thecon::VERSION).not_to be_empty
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "::ready?" do
|
11
|
+
it "exists" do
|
12
|
+
expect(Thecon::respond_to? :ready?).to eq(true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns true for an known and valid IP" do
|
16
|
+
expect(Thecon::ready?(80, "www.google.com") ).to eq(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false for an invalid IP" do
|
20
|
+
expect(Thecon::ready?(80, "192.0.2.0") ).to eq(false)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/thecon.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'thecon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "thecon"
|
8
|
+
gem.version = Thecon::VERSION
|
9
|
+
gem.authors = ["tnarik"]
|
10
|
+
gem.email = ["tnarik@gmail.com"]
|
11
|
+
gem.description = %q{Simple connection checker to find out if a server is available at a certain port}
|
12
|
+
gem.summary = %q{Attempt a connection to a certain IP (or hostname), port}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# devevelopment dependencies
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thecon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tnarik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Simple connection checker to find out if a server is available at a certain
|
28
|
+
port
|
29
|
+
email:
|
30
|
+
- tnarik@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- .rspec
|
37
|
+
- .ruby-gemset
|
38
|
+
- .ruby-version
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/thecon.rb
|
44
|
+
- lib/thecon/version.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
- spec/thecon_spec.rb
|
47
|
+
- thecon.gemspec
|
48
|
+
homepage: ''
|
49
|
+
licenses: []
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.0.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Attempt a connection to a certain IP (or hostname), port
|
71
|
+
test_files:
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- spec/thecon_spec.rb
|