ping-rb 0.1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ping-rb.rb +254 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7c99dd6d44b4628af4564134ed35c2e9370826cecbde495a31dafc46ab356144
4
+ data.tar.gz: be1ac4c991e9070fbf421ec9c01e759056f521466adea3ee0cffae13fee920bf
5
+ SHA512:
6
+ metadata.gz: c5a40fafe24105e5e9e8b33774e5099d96f02df9ba7e9a45519a27bd079711459065a5675b90e07fe243dab633d05afbb018381392f8ca3214af8c3284a5d01e
7
+ data.tar.gz: 517b55b78e38be72e444025a9db7edba3122608afc96e9adebac2cd31a8540638429d7a7ff3a85df5df4817ddc554eed78f14f7e766d899a5ebf4d5fc18c9f43
data/lib/ping-rb.rb ADDED
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'net/ping'
4
+ require 'optparse'
5
+ require 'colorize'
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ # NOTE: Explain the Ping-rb
10
+ opts.banner = "Explain: Send ICMP ECHO_REQUEST to network hosts\n------------------------------------------------\nAuthor: Meisam Heidari\nGithub: https://github.com/Mr-Fox-h\nGitlab: https://gitlab.com/mr-fox-h\nBitbucket: https://bitbucket.org/mr-fox-h\n------------------------------------------------\n"
11
+ # NOTE: Ping the external IP (FOR 10 TIME)
12
+ opts.on('-e', '--external NAME', 'External ping') do |host_external_option|
13
+ puts "\nPing the external IP (FOR 10 TIME)\n----------------------------------\n"
14
+ puts "IP\t\t\t statuse\n----------------|-----------------"
15
+ 10.times do
16
+ check = Net::Ping::External.new(host_external_option)
17
+ if check.ping? == true
18
+ puts host_external_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
19
+ else
20
+ puts host_external_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
21
+ end
22
+ end
23
+ end
24
+ # NOTE: Ping the external IP (YOU CAN PING FOR EVER)
25
+ opts.on('-E', '--external-loop NAME', 'External ping (LOOP)') do |host_external_loop_option|
26
+ puts "\nPing the external IP (LOOP)\n----------------------------------\n"
27
+ puts "IP\t\t\t statuse\n----------------|-----------------"
28
+ loop do
29
+ check = Net::Ping::External.new(host_external_loop_option)
30
+ if check.ping? == true
31
+ puts host_external_loop_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
32
+ else
33
+ puts host_external_loop_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
34
+ end
35
+ end
36
+ end
37
+ # NOTE: Ping the HTTP ADDRESS (FOR 10 TIMES)
38
+ opts.on('-h', '--http NAME', 'HTTP ping (FOR 10 TIMES)') do |host_http_option|
39
+ puts "\nPing the HTTP ADDRESS (FOR 10 TIME)\n----------------------------------\n"
40
+ puts "Address\t\t\t statuse\n----------------|-----------------"
41
+ 10.times do
42
+ check = Net::Ping::HTTP.new(host_http_option)
43
+ if check.ping? == true
44
+ puts host_http_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
45
+ else
46
+ puts host_http_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
47
+ end
48
+ end
49
+ end
50
+ # NOTE: Ping the HTTP ADDRESS (LOOP)
51
+ opts.on('-H', '--http-loop NAME', 'HTTP ping (LOOP)') do |host_http_loop_option|
52
+ puts "\nPing the HTTP ADDRESS (LOOP)\n----------------------------------\n"
53
+ puts "Address\t\t\t statuse\n----------------|-----------------"
54
+ loop do
55
+ check = Net::Ping::HTTP.new(host_http_loop_option)
56
+ if check.ping? == true
57
+ puts host_http_loop_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
58
+ else
59
+ puts host_http_loop_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
60
+ end
61
+ end
62
+ end
63
+ # NOTE: Ping the TCP ADDRESS/IP (FOR 10 TIMES)
64
+ opts.on('-t', '--tcp NAME', 'TCP ping (FOR 10 TIMES)') do |host_tcp_option|
65
+ puts "\nPing the ADDRESS/IP (FOR 10 TIMES)\n----------------------------------\n"
66
+ puts "Address/IP\t\t statuse\n----------------|-----------------"
67
+ 10.times do
68
+ check = Net::Ping::TCP.new(host_tcp_option)
69
+ if check.ping? == true
70
+ puts host_tcp_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
71
+ else
72
+ puts host_tcp_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
73
+ end
74
+ end
75
+ end
76
+ # NOTE: Ping the TCP ADDRESS/IP (LOOP)
77
+ opts.on('-T', '--tcp-loop NAME', 'TCP ping (LOOP)') do |_host_tcp_Loop_option|
78
+ puts "\nPing the ADDRESS/IP (LOOP)\n----------------------------------\n"
79
+ puts "Address/IP\t\t statuse\n----------------|-----------------"
80
+ loop do
81
+ check = Net::Ping::TCP.new(host_tcp_loop_option)
82
+ if check.ping? == true
83
+ puts host_tcp_loop_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
84
+ else
85
+ puts host_tcp_loop_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
86
+ end
87
+ end
88
+ end
89
+ # NOTE: Ping the UDP ADDRESS/IP (FOR 10 TIMES)
90
+ opts.on('-u', '--udp NAME', 'TCP ping (FOR 10 TIMES)') do |host_udp_option|
91
+ puts "\nPing the ADDRESS/IP (FOR 10 TIMES)\n----------------------------------\n"
92
+ puts "Address/IP\t\t statuse\n----------------|-----------------"
93
+ 10.times do
94
+ check = Net::Ping::UDP.new(host_udp_option)
95
+ if check.ping? == true
96
+ puts host_udp_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
97
+ else
98
+ puts host_udp_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
99
+ end
100
+ end
101
+ end
102
+ # NOTE: Ping the UDP ADDRESS/IP (LOOP)
103
+ opts.on('-u', '--udp NAME', 'TCP ping (LOOP)') do |host_udp_loop_option|
104
+ puts "\nPing the ADDRESS/IP (LOOP)\n----------------------------------\n"
105
+ puts "Address/IP\t\t statuse\n----------------|-----------------"
106
+ loop do
107
+ check = Net::Ping::UDP.new(host_udp_option)
108
+ if check.ping? == true
109
+ puts host_udp_loop_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
110
+ else
111
+ puts host_udp_loop_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
112
+ end
113
+ end
114
+ end
115
+ # NOTE: Verbose command for external ping
116
+ opts.on('--verbose-e NAME', 'Verbose output for External ping') do |host_verbose_external_option|
117
+ 5.times do
118
+ check = Net::Ping::External.new(host_verbose_external_option)
119
+ if check.ping? == true
120
+ puts host_verbose_external_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
121
+ print 'Timeout:'
122
+ p check.timeout
123
+ print 'Duration:'
124
+ p check.duration
125
+ print 'Port:'
126
+ p check.port
127
+ print 'warning: '
128
+ p check.warning
129
+ print 'Exception: '
130
+ p check.exception
131
+ puts '-------------------------------------------------------------------------------------------'
132
+ else
133
+ puts host_verbose_external_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
134
+ print 'Timeout:'
135
+ p check.timeout
136
+ print 'Duration:'
137
+ p check.duration
138
+ print 'Port:'
139
+ p check.port
140
+ print 'warning: '
141
+ p check.warning
142
+ print 'Exception: '
143
+ p check.exception
144
+ puts '-------------------------------------------------------------------------------------------'
145
+ end
146
+ end
147
+ end
148
+ # NOTE: Verbose command for HTTP ping
149
+ opts.on('--verbose-h NAME', 'Verbose output for HTTP ping') do |host_verbose_http_option|
150
+ 5.times do
151
+ check = Net::Ping::HTTP.new(host_verbose_http_option)
152
+ if check.ping? == true
153
+ puts host_verbose_http_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
154
+ print 'Timeout:'
155
+ p check.timeout
156
+ print 'Duration:'
157
+ p check.duration
158
+ print 'Port:'
159
+ p check.port
160
+ print 'warning: '
161
+ p check.warning
162
+ print 'Exception: '
163
+ p check.exception
164
+ puts '-------------------------------------------------------------------------------------------'
165
+ else
166
+ puts host_verbose_http_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
167
+ print 'Timeout:'
168
+ p check.timeout
169
+ print 'Duration:'
170
+ p check.duration
171
+ print 'Port:'
172
+ p check.port
173
+ print 'warning: '
174
+ p check.warning
175
+ print 'Exception: '
176
+ p check.exception
177
+ puts '-------------------------------------------------------------------------------------------'
178
+ end
179
+ end
180
+ end
181
+ # NOTE: Verbose command for TCP ping
182
+ opts.on('--verbose-t NAME', 'Verbose output for TCP ping') do |host_verbose_tcp_option|
183
+ 5.times do
184
+ check = Net::Ping::TCP.new(host_verbose_tcp_option)
185
+ if check.ping? == true
186
+ puts host_verbose_tcp_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
187
+ print 'Timeout:'
188
+ p check.timeout
189
+ print 'Duration:'
190
+ p check.duration
191
+ print 'Port:'
192
+ p check.port
193
+ print 'warning: '
194
+ p check.warning
195
+ print 'Exception: '
196
+ p check.exception
197
+ puts '-------------------------------------------------------------------------------------------'
198
+ else
199
+ puts host_verbose_tcp_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
200
+ print 'Timeout:'
201
+ p check.timeout
202
+ print 'Duration:'
203
+ p check.duration
204
+ print 'Port:'
205
+ p check.port
206
+ print 'warning: '
207
+ p check.warning
208
+ print 'Exception: '
209
+ p check.exception
210
+ puts '-------------------------------------------------------------------------------------------'
211
+ end
212
+ end
213
+ end
214
+ # NOTE: Verbose command for UDP ping
215
+ opts.on('--verbose-u NAME', 'Verbose output for UDP ping') do |host_verbose_udp_option|
216
+ 5.times do
217
+ check = Net::Ping::TCP.new(host_verbose_udp_option)
218
+ if check.ping? == true
219
+ puts host_verbose_udp_option.to_s.colorize(:light_blue) + "\t\t\tUP".colorize(:green)
220
+ print 'Timeout:'
221
+ p check.timeout
222
+ print 'Duration:'
223
+ p check.duration
224
+ print 'Port:'
225
+ p check.port
226
+ print 'warning: '
227
+ p check.warning
228
+ print 'Exception: '
229
+ p check.exception
230
+ puts '-------------------------------------------------------------------------------------------'
231
+ else
232
+ puts host_verbose_udp_option.to_s.colorize(:light_blue) + "\t\t\tDOWN".colorize(:red)
233
+ print 'Timeout:'
234
+ p check.timeout
235
+ print 'Duration:'
236
+ p check.duration
237
+ print 'Port:'
238
+ p check.port
239
+ print 'warning: '
240
+ p check.warning
241
+ print 'Exception: '
242
+ p check.exception
243
+ puts '-------------------------------------------------------------------------------------------'
244
+ end
245
+ end
246
+ end
247
+ # NOTE: Help option
248
+ opts.on('-a', '--aid', '--help', 'Print this help') do
249
+ puts opts
250
+ exit
251
+ end
252
+ end.parse!
253
+
254
+ options
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ping-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Meisam Heidari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: It's a simple, but useful tool to ping computers and systems.
14
+ email: mr.fox@iran.ir
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ping-rb.rb
20
+ homepage: https://rubygems.org/gems/ping-rb
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.0
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 1.8.11
38
+ requirements: []
39
+ rubygems_version: 3.3.15
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Ping with Ruby!
43
+ test_files: []