internet_tools 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4f7425724e42d040c033989ce15475492d8ec865f91717e52048f57f24f1716b
4
+ data.tar.gz: 703bbc6fb9bb3a861ac156250f13a9dcb8fa29d291b44c75e0eef481ffb2e62d
5
+ SHA512:
6
+ metadata.gz: e1cf148daed98d6bbafe559e7074a671ded394c55cc8eb6acf64baf96851b4e08340b05d619d0dfe03ffaa3d8cb9bea4860f1bcf772606ac1c8d7c232ae5f382
7
+ data.tar.gz: 70d33184482dd2fb8702d1197294bc5109f5bc23fbc89c8d9dee2f669272f806ef877aaf4f74e3199973bada10e14de358f5ba038614f256446e450288443460
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2021 Deepak Chauhan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ ==== ************* Internet Tools *************
2
+
3
+ A tool to include internet queries in your ruby projects.
4
+
5
+
6
+ ==== Features
7
+ - Nslookup
8
+ - Ip addresses
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rdoc/task'
2
+
3
+ task :test do
4
+ sh "rspec -f documentation"
5
+ end
6
+
7
+ RDoc::Task.new do |rdoc|
8
+ rdoc.main = "README.rdoc"
9
+ rdoc.rdoc_files.include("README.rdoc", "lib/*")
10
+ rdoc.rdoc_dir = 'documentation'
11
+ end
12
+
13
+ task :build_gem do
14
+ Rake::Task[:test].execute
15
+ sh "gem build internet_tools.gemspec"
16
+ end
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+ This file contains all the changes made in the gem as per update.
3
+
4
+
5
+ ## 0.1.1 - 05-03-2021
6
+ #### Changed
7
+ - gemspec file for latest changes.
8
+ - See 0.1.0 for major changes.
9
+
10
+ ## 0.1.0 - 05-03-2021
11
+ #### Added
12
+ - getIp() functionality.
13
+ #### Updated
14
+ - Tests
15
+ - gemspec as now it requires socket as dependency.
@@ -0,0 +1,48 @@
1
+ require 'socket'
2
+
3
+ # InternetTools class contains different internet tools.
4
+ class InternetTools
5
+ # This method returns hash containing dns lookup for a given url.
6
+ #
7
+ # ====Params:
8
+ # url (string) : URL fir which dns search is required
9
+ # customDNS (string) (optional) : Custom DNS, if query needs to be done from custome dns
10
+ #
11
+ # ====Returns:
12
+ # [Hash] : A hash containing lookup data is returned. Hash structure is as follows
13
+ # 1. First Key is 'server' which returns the DNS server which is being contacted.
14
+ # 2. Second Key is 'address' which returns the DNS server's physical address.
15
+ # 3. A hash containing DNS lookup index number wise.
16
+
17
+ def nslookup(url, customDNS="")
18
+ query = "nslookup #{url} #{customDNS}"
19
+ result = IO.popen(query).read().gsub("\t","").split("\n")
20
+ output = {}
21
+ output["server"] = result[0].split(":")[1]
22
+ output["address"] = result[1].split(":")[1]
23
+ # Finding start of addresses
24
+ output["ip details"] = {}
25
+ ip_index = 0
26
+ for ind in 2...result.length do
27
+ if result[ind].start_with?("Name") == true
28
+ ip_data = {}
29
+ ip_data["name"] = result[ind].split(":")[1]
30
+ ip_data["address"] = result[ind+1].split(":")[1..].join(":")
31
+ output["ip details"][ip_index.to_s] = ip_data
32
+ ip_index+=1
33
+ end
34
+ end
35
+ output
36
+ end
37
+
38
+ # This method returns all the IP addresses related to machine
39
+ # ====Returns
40
+ # [Array] - This method returns a list of IP address as string.
41
+ def get_IP
42
+ ip_list = []
43
+ Socket.ip_address_list.each do |address|
44
+ ip_list.push(address.ip_address)
45
+ end
46
+ ip_list
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+ require 'rspec'
2
+ require '../lib/internet_tools'
3
+ require 'webmock/rspec'
4
+
5
+ RSpec.describe "tests for internet tools" do
6
+ let(:internetTools){InternetTools.new}
7
+ let(:mock) {double(internetTools)}
8
+
9
+ context "# nslookup " do
10
+ let(:validURL){"cerner.com"}
11
+ let(:invalidURL){"github"}
12
+
13
+ context "When user does not provides custom DNS" do
14
+
15
+ it "program returns lookup for valid URL" do
16
+ output = {"server"=>"172.23.160.1", "address"=>"172.23.160.1#53", "ip details"=>{"0"=>{"name"=>"cerner.com", "address"=>" 10.182.234.43"}, "1"=>{"name"=>"cerner.com", "address"=>" 10.181.204.21"}, "2"=>{"name"=>"cerner.com", "address"=>" 10.160.203.34"}, "3"=>{"name"=>"cerner.com", "address"=>" 10.171.34.154"}, "4"=>{"name"=>"cerner.com", "address"=>" 10.181.192.57"}, "5"=>{"name"=>"cerner.com", "address"=>" 10.182.237.203"}, "6"=>{"name"=>"cerner.com", "address"=>" 10.162.203.98"}, "7"=>{"name"=>"cerner.com", "address"=>" 10.181.161.135"}, "8"=>{"name"=>"cerner.com", "address"=>" 159.140.213.101"}, "9"=>{"name"=>"cerner.com", "address"=>" 159.140.2.66"}, "10"=>{"name"=>"cerner.com", "address"=>" 159.140.213.79"}, "11"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::ab6:ea2b"}, "12"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::ab5:cc15"}, "13"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::aa0:cb22"}, "14"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::aab:229a"}, "15"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::ab5:c039"}, "16"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::ab6:edcb"}, "17"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::aa2:cb62"}, "18"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::ab5:a187"}, "19"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::9f8c:d565"}, "20"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::9f8c:242"}, "21"=>{"name"=>"cerner.com", "address"=>" fd24:5310:6106:7777::9f8c:d54f"}}}
17
+ allow(mock).to receive(:nslookup) {output}
18
+ expect(mock.nslookup validURL).to include(output)
19
+ end
20
+
21
+ it "program returns empty lookup for inavlid url" do
22
+ output = {"server"=>"172.23.160.1", "address"=>"172.23.160.1#53", "ip details"=>{}}
23
+ expect(internetTools.nslookup invalidURL).to include(output)
24
+ end
25
+
26
+ end
27
+
28
+ context "When user does provides custom DNS" do
29
+ let(:customDNS) { "1.1.1.1" }
30
+ it "programs returns lookup for valid URL" do
31
+ output = {"server"=>"1.1.1.1", "address"=>"1.1.1.1#53", "ip details"=>{"0"=>{"name"=>"cerner.com", "address"=>" 159.140.213.205"}}}
32
+ expect(internetTools.nslookup validURL,customDNS).to include(output)
33
+ end
34
+ it "program returns empty lookup for inavlid url" do
35
+ output = {"server"=>"1.1.1.1", "address"=>"1.1.1.1#53", "ip details"=>{}}
36
+ expect(internetTools.nslookup invalidURL,customDNS).to include(output)
37
+ end
38
+ end
39
+ end
40
+
41
+ context "# getIP " do
42
+ it "program returns IP addresses" do
43
+ allow(mock).to receive(:get_IP) {["127.0.0.1", "192.168.0.1"]}
44
+ expect(mock.get_IP).to match(["127.0.0.1", "192.168.0.1"])
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: internet_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Deepak Chauhan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-05 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ description: A tool for that allows you to use system internet tools in your ruby
28
+ project.
29
+ email: deepakchauhan878@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - changelog-0-1-1.md
38
+ - lib/internet_tools.rb
39
+ - spec/internet_tools_spec.rb
40
+ homepage: https://github.com/royaleagle73/internet_tools
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.1.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A tool for implementing internet tools in ruby projetcs
63
+ test_files: []