pingman 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ec6ce7607a57801924c408e6c78a3f8c5bc003a
4
+ data.tar.gz: 0bb6d40920a994ca6f99e09f40fe4edc281b27e2
5
+ SHA512:
6
+ metadata.gz: 70b8ba342b7537faac02435373af2e2364ae0da3368cf24e8cfb4a163f4f263e74a3493fd856a960b7dc1f56bdbe7a0ab394d17d26ee16f4bb179870f96af92a
7
+ data.tar.gz: 56c170559f64a8fd5d0e19468aaa1408ffd5d8337e0f092ca05a71b58d63ae010e2685d3b9a3bbc1d5cadb063042592cf6b5456a57386367196eb0c554f109bb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pingman.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kurochan
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
+ # Pingman
2
+
3
+ Ping CUI tool
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pingman'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pingman
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/kurochan/pingman/fork )
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/bin/pingman ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pingman'
4
+ Signal.trap(:INT){
5
+ exit 0
6
+ }
7
+ Pingman.pingman
data/lib/pingman.rb ADDED
@@ -0,0 +1,68 @@
1
+ require "pingman/version"
2
+
3
+ require "pingman/line"
4
+ require "pingman/screen"
5
+ require "pingman/pinger"
6
+
7
+ module Pingman
8
+ def self.pingman
9
+ pinger = Pinger.new
10
+ screen = Screen.new
11
+
12
+ line = Line.new
13
+ line.hostname = 'local'
14
+ line.address = '127.0.0.1'
15
+ line.row = screen.lines.size
16
+ screen.lines.push line
17
+ line = Line.new
18
+ line.hostname = 'google dns'
19
+ line.address = '8.8.8.8'
20
+ line.row = screen.lines.size
21
+ screen.lines.push line
22
+ line = Line.new
23
+ line.hostname = 'not found'
24
+ line.address = '1.2.3.4'
25
+ line.row = screen.lines.size
26
+ screen.lines.push line
27
+ line = Line.new
28
+ line.hostname = 'google dns'
29
+ line.address = '8.8.4.4'
30
+ line.row = screen.lines.size
31
+ screen.lines.push line
32
+ line = Line.new
33
+ line.hostname = 'google.com'
34
+ line.row = screen.lines.size
35
+ screen.lines.push line
36
+ line = Line.new
37
+ line.hostname = 'yahoo.com'
38
+ line.row = screen.lines.size
39
+ screen.lines.push line
40
+ line = Line.new
41
+ line.hostname = 'microsoft.com'
42
+ line.row = screen.lines.size
43
+ screen.lines.push line
44
+
45
+ Thread.new do
46
+ screen.update
47
+ loop do
48
+ screen.lines.each do |line|
49
+ line.sending = true
50
+ screen.update_line line
51
+ pinger.ping line
52
+ sleep 0.5
53
+ line.sending = false
54
+ screen.update_line line
55
+ end
56
+ sleep 1
57
+ end
58
+ end
59
+
60
+ begin
61
+ loop do
62
+ break if screen.getch == 'q'
63
+ end
64
+ ensure
65
+ screen.close_screen
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,15 @@
1
+ class Line
2
+ attr_accessor :hostname, :address, :res, :loss, :rtt, :avg, :snt, :log, :sending, :row
3
+ def initialize
4
+ @hostname = nil
5
+ @address = nil
6
+ @res = true
7
+ @loss = 0.0
8
+ @rtt = 0
9
+ @avg = 0
10
+ @snt = 0
11
+ @log = []
12
+ @sending = false
13
+ @row = 0
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'net/ping'
2
+
3
+ class Pinger
4
+ def ping(line)
5
+ return unless line.hostname || line.address
6
+ line.log = line.log.slice(0, 14)
7
+ pe = Net::Ping::External.new(line.address || line.hostname)
8
+ start = Time.now
9
+ line.res = pe.ping
10
+ line.rtt = Time.now - start
11
+ line.loss = (line.snt * line.loss + (line.res ? 0 : 1)) / (line.snt + 1).to_f
12
+ line.avg = (line.snt * line.avg + line.rtt) / (line.snt + 1).to_f if line.res
13
+ line.snt += 1
14
+ line.log.unshift line.res
15
+ end
16
+ end
@@ -0,0 +1,148 @@
1
+ require 'curses'
2
+ require 'socket'
3
+
4
+ class Screen
5
+ include Curses
6
+ attr_accessor :lines
7
+ public :getch, :close_screen
8
+
9
+ TOP_OFFSET = 0
10
+ LETF_OFFSET = 2
11
+ RIGHT_OFFSET = 5
12
+ TIME_LOW = 1
13
+ HOSTNAME_WIDTH = 15
14
+ RESULT_WIDTH = 15
15
+ COL_OFFSET = 3
16
+
17
+ def initialize
18
+ init_screen
19
+ start_color
20
+ Curses.init_pair 1, COLOR_WHITE, COLOR_GREEN
21
+ Curses.init_pair 2, COLOR_WHITE, COLOR_RED
22
+ curs_set 0
23
+ noecho
24
+ sleep 0.05
25
+ @lines = []
26
+ @current_cols = cols
27
+ @hostname = Socket.gethostname
28
+ @hostaddr = Socket.getaddrinfo(Socket::gethostname, nil, Socket::AF_INET)[0][3]
29
+ update
30
+ end
31
+
32
+ def print_header(line_num)
33
+ title = 'Ping Man'
34
+ setpos(line_num, (cols - title.length) / 2)
35
+ addstr(title)
36
+ line_num += 1
37
+
38
+ host = "#{@hostname}(#{@hostaddr})"
39
+ setpos(line_num, LETF_OFFSET)
40
+ addstr(host)
41
+ line_num += 1
42
+
43
+ usage = 'Keytype: [a] Display addr, [i] ping interval, [t] ping timeout, [q]uit'
44
+ setpos(line_num, LETF_OFFSET)
45
+ addstr(usage)
46
+ line_num += 1
47
+
48
+ line_num += 1
49
+
50
+ offset = LETF_OFFSET
51
+ setpos(line_num, offset)
52
+ addstr('HOSTNAME')
53
+ offset += HOSTNAME_WIDTH
54
+ setpos(line_num, offset)
55
+ addstr('ADDRESS')
56
+ offset = cols - RIGHT_OFFSET - RESULT_WIDTH
57
+ setpos(line_num, offset)
58
+ addstr('RESULT')
59
+ offset -= 'SNT'.length + COL_OFFSET
60
+ setpos(line_num, offset)
61
+ addstr('SNT')
62
+ offset -= 'AVG'.length + COL_OFFSET
63
+ setpos(line_num, offset)
64
+ addstr('AVG')
65
+ offset -= 'RTT'.length + COL_OFFSET
66
+ setpos(line_num, offset)
67
+ addstr('RTT')
68
+ offset -= 'LOSS%'.length + COL_OFFSET
69
+ setpos(line_num, offset)
70
+ addstr('LOSS%')
71
+ line_num += 1
72
+ end
73
+
74
+ def print_line(line)
75
+ setpos(@lines_low + line.row, 0)
76
+ deleteln
77
+ refresh
78
+ insertln
79
+ attron(A_BLINK) unless line.res
80
+ setpos(@lines_low + line.row, LETF_OFFSET - 2)
81
+ addstr('> ') if line.sending
82
+ offset = LETF_OFFSET
83
+ setpos(@lines_low + line.row, offset)
84
+ addstr(line.hostname.to_s)
85
+ offset += HOSTNAME_WIDTH
86
+ setpos(@lines_low + line.row, offset)
87
+ addstr(line.address.to_s)
88
+ offset = cols - RIGHT_OFFSET - RESULT_WIDTH
89
+ setpos(@lines_low + line.row, offset)
90
+ addstr(line.log.slice(0, 15).map{|c| c ? '.' : '!'}.join)
91
+ offset -= 'SNT'.length + COL_OFFSET
92
+ setpos(@lines_low + line.row, offset + 'SNT'.length - line.snt.to_s.length)
93
+ addstr(line.snt.to_s)
94
+ offset -= 'AVG'.length + COL_OFFSET
95
+ avg = (line.avg * 1000).round.to_s
96
+ setpos(@lines_low + line.row, offset + 'AVG'.length - avg.length)
97
+ addstr(avg)
98
+ offset -= 'RTT'.length + COL_OFFSET
99
+ rtt = (line.rtt * 1000).round.to_s
100
+ setpos(@lines_low + line.row, offset + 'RTT'.length - rtt.length)
101
+ addstr(rtt)
102
+ offset -= 'LOSS%'.length + COL_OFFSET
103
+ loss = "#{sprintf('%.1f',line.loss * 100)}%"
104
+ setpos(@lines_low + line.row, offset + 'LOSS%'.length - loss.length)
105
+ addstr(loss)
106
+ offset -= ' OK '.length + COL_OFFSET
107
+ setpos(@lines_low + line.row, offset)
108
+ if line.res
109
+ attron(color_pair(1))
110
+ addstr(' OK ')
111
+ else
112
+ attron(color_pair(2))
113
+ addstr(' NG ')
114
+ end
115
+ attroff(A_COLOR)
116
+ attroff(A_BLINK)
117
+ end
118
+
119
+ def print_lines
120
+ @lines.each do |line|
121
+ print_line line
122
+ end if @lines
123
+ end
124
+
125
+ def print_time(line_num)
126
+ time = "[last update #{Time.now.strftime("%m-%d %H:%M:%S")}]"
127
+ setpos(line_num, cols - time.length - RIGHT_OFFSET)
128
+ addstr(time)
129
+ line_num += 1
130
+ end
131
+
132
+ def update
133
+ clear
134
+ @lines_low = print_header(TOP_OFFSET)
135
+ print_lines
136
+ refresh
137
+ end
138
+
139
+ def update_line(line)
140
+ if @current_cols != cols
141
+ @current_cols = cols
142
+ update
143
+ end
144
+ print_line line
145
+ print_time TIME_LOW
146
+ refresh
147
+ end
148
+ end
@@ -0,0 +1,3 @@
1
+ module Pingman
2
+ VERSION = "0.0.2"
3
+ end
data/pingman.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pingman/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pingman"
8
+ spec.version = Pingman::VERSION
9
+ spec.authors = ["kurochan"]
10
+ spec.email = ["kuro@kurochan.org"]
11
+ spec.summary = %q{Ping check tool.}
12
+ spec.description = %q{Ping check tool.}
13
+ spec.homepage = "https://github.com/kurochan/pingman"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "net-ping"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pingman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - kurochan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ping
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ping check tool.
56
+ email:
57
+ - kuro@kurochan.org
58
+ executables:
59
+ - pingman
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/pingman
69
+ - lib/pingman.rb
70
+ - lib/pingman/line.rb
71
+ - lib/pingman/pinger.rb
72
+ - lib/pingman/screen.rb
73
+ - lib/pingman/version.rb
74
+ - pingman.gemspec
75
+ homepage: https://github.com/kurochan/pingman
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ping check tool.
99
+ test_files: []
100
+ has_rdoc: