coaping 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/bin/coaping +55 -0
- data/coaping.gemspec +13 -0
- metadata +71 -0
data/README.md
ADDED
data/bin/coaping
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
def inms(t)
|
7
|
+
"#{"%2.1f" % [t * 1000.0]} ms"
|
8
|
+
end
|
9
|
+
|
10
|
+
def ins(t)
|
11
|
+
"#{t} second#{t == 1 ? "" : "s"}"
|
12
|
+
end
|
13
|
+
|
14
|
+
dest = ARGV[0]
|
15
|
+
fail "usage: coaping addr [port [timeout [ntry]]]" unless dest
|
16
|
+
port = Integer(ARGV[1] || 5683)
|
17
|
+
maxtime = Float(ARGV[2] || 1)
|
18
|
+
maxnum = Integer(ARGV[3] || 20)
|
19
|
+
|
20
|
+
begin
|
21
|
+
u = UDPSocket.new(Socket::AF_INET6)
|
22
|
+
u.connect(dest, port)
|
23
|
+
rescue
|
24
|
+
u = UDPSocket.new(Socket::AF_INET)
|
25
|
+
u.connect(dest, port)
|
26
|
+
end
|
27
|
+
|
28
|
+
puts "Trying #{maxnum} times with #{dest} at port #{port}, waiting #{ins(maxtime)} max:"
|
29
|
+
|
30
|
+
t = []
|
31
|
+
|
32
|
+
maxnum.times do |n|
|
33
|
+
begin
|
34
|
+
t[n] = Time.now
|
35
|
+
u.send [0b01000000, 0, n].pack("CCn"), 0
|
36
|
+
response, addr = timeout(maxtime) { u.recvfrom(100) }
|
37
|
+
if response.bytesize != 4
|
38
|
+
p [response, addr]
|
39
|
+
else
|
40
|
+
hd, code, seq = response.unpack("CCn")
|
41
|
+
if hd != 0b01110000 || code != 0 || seq != n
|
42
|
+
p [(inms(Time.now-t[seq]) rescue "-"), [hd.to_s(2), code, seq], addr]
|
43
|
+
else
|
44
|
+
puts "#{"%3d" % n} #{inms(Time.now - t[n])} #{addr[2]}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
rescue Timeout::Error => e
|
48
|
+
puts "no response after #{ins(maxtime)}"
|
49
|
+
rescue SystemCallError => e
|
50
|
+
puts e # e.class.name
|
51
|
+
rescue Interrupt => e
|
52
|
+
puts e
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
end
|
data/coaping.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
spec = Gem::Specification.new do |s|
|
2
|
+
s.name = 'coaping'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.summary = "coaping: a ping for CoAP, the Constrained Application Protocol."
|
5
|
+
s.description = %{coaping: check whether your CoAP server is still there.}
|
6
|
+
s.files = %w(README.md coaping.gemspec bin/coaping)
|
7
|
+
s.executables = ['coaping']
|
8
|
+
s.default_executable = 'coaping'
|
9
|
+
s.required_ruby_version = '>= 1.8.6'
|
10
|
+
s.author = "Carsten Bormann"
|
11
|
+
s.email = "cabo@tzi.org"
|
12
|
+
s.homepage = "http://github.com/cabo/coaping"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coaping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Carsten Bormann
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-11-19 00:00:00 +01:00
|
19
|
+
default_executable: coaping
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "coaping: check whether your CoAP server is still there."
|
23
|
+
email: cabo@tzi.org
|
24
|
+
executables:
|
25
|
+
- coaping
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- README.md
|
32
|
+
- coaping.gemspec
|
33
|
+
- bin/coaping
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/cabo/coaping
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 59
|
49
|
+
segments:
|
50
|
+
- 1
|
51
|
+
- 8
|
52
|
+
- 6
|
53
|
+
version: 1.8.6
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.7
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: "coaping: a ping for CoAP, the Constrained Application Protocol."
|
70
|
+
test_files: []
|
71
|
+
|