UPnP-IGD 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-06-28
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,9 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/upnp_igd
6
+ lib/UPnP/control/device/internet_gateway_device.rb
7
+ lib/UPnP/control/service/layer_3_forwarding.rb
8
+ lib/UPnP/control/service/wan_common_interface_config.rb
9
+ lib/UPnP/control/service/wan_ip_connection.rb
@@ -0,0 +1,71 @@
1
+ = UPnP-IGD
2
+
3
+ * http://seattlerb.org/UPnP-IGD
4
+ * Eric Hodel drbrain@segment7.net
5
+ * http://www.upnp.org/standardizeddcps/igd.asp
6
+ * Bugs: http://rubyforge.org/tracker/?atid=5921&group_id=1513
7
+
8
+ == DESCRIPTION:
9
+
10
+ A UPnP extension for Internet Gateway Devices
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ * Command-line utility that displays information about a UPnP gateway
15
+ * Example of using some UPnP APIs
16
+ * Does not set anything on the device
17
+ * Only tested against miniupnpd
18
+
19
+ == SYNOPSIS:
20
+
21
+ $ upnp_igd
22
+ Gateway at http://10.1.1.1/
23
+ Connected, up since 2008-06-29 03:31:00 (66123 seconds)
24
+ Connection type: IP_Routed
25
+ 384 Kb/s up, 1536 Kb/s down
26
+ External IP address: 10.255.255.254
27
+
28
+ Port mappings:
29
+ 0 UDP *:4502 -> 10.1.1.2:4500 "iC4502"
30
+ 1 UDP *:5355 -> 10.1.1.2:5353 "iC5355"
31
+ 2 UDP *:58712 -> 10.1.1.3:58712 "Skype UDP at 10.1.1.3:58712 (546)"
32
+ 3 TCP *:58712 -> 10.1.1.3:58712 "Skype TCP at 10.1.1.3:58712 (546)"
33
+ 4 UDP *:5353 -> 10.1.1.4:5353 "iC5353"
34
+
35
+ == REQUIREMENTS:
36
+
37
+ * A UPnP gateway device
38
+
39
+ == INSTALL:
40
+
41
+ * sudo gem install UPnP-IGD
42
+
43
+ == LICENSE:
44
+
45
+ All code copyright 2008 Eric Hodel. All rights reserved.
46
+
47
+ Redistribution and use in source and binary forms, with or without
48
+ modification, are permitted provided that the following conditions
49
+ are met:
50
+
51
+ 1. Redistributions of source code must retain the above copyright
52
+ notice, this list of conditions and the following disclaimer.
53
+ 2. Redistributions in binary form must reproduce the above copyright
54
+ notice, this list of conditions and the following disclaimer in the
55
+ documentation and/or other materials provided with the distribution.
56
+ 3. Neither the names of the authors nor the names of their contributors
57
+ may be used to endorse or promote products derived from this software
58
+ without specific prior written permission.
59
+
60
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
61
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
62
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
64
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
65
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
66
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
67
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
68
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
69
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
70
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
71
+
@@ -0,0 +1,14 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ $:.unshift 'lib'
6
+ require 'UPnP/control/device/internet_gateway_device'
7
+
8
+ Hoe.new('UPnP-IGD',
9
+ UPnP::Control::Device::InternetGatewayDevice::VERSION) do |p|
10
+ p.rubyforge_name = 'seattlerb'
11
+ p.developer('Eric Hodel', 'drbrain@segment7.net')
12
+ end
13
+
14
+ # vim: syntax=Ruby
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'UPnP/control/device/internet_gateway_device'
4
+
5
+ ssdp = UPnP::SSDP.new
6
+ timeout = ARGV.shift
7
+ timeout = if timeout then
8
+ begin
9
+ timeout = Integer timeout
10
+ rescue
11
+ abort <<-EOF
12
+ Usage: #{$0} [timeout]
13
+
14
+ Prints information about UPnP internet gateway devices
15
+ EOF
16
+ end
17
+ else
18
+ 1
19
+ end
20
+
21
+ ssdp.timeout = timeout
22
+
23
+ gateways = UPnP::Control::Device::InternetGatewayDevice.search ssdp
24
+
25
+ if gateways.empty? then
26
+ puts 'No internet gateway devices found'
27
+ else
28
+ gateways.each do |igd| igd.print_info end
29
+ end
30
+
@@ -0,0 +1,125 @@
1
+ require 'rubygems'
2
+ require 'UPnP/control/device'
3
+ require 'UPnP/control/service/layer_3_forwarding'
4
+ require 'UPnP/control/service/wan_ip_connection'
5
+ require 'UPnP/control/service/wan_common_interface_config'
6
+
7
+ ##
8
+ # A UPnP Internet Gateway Device control point that provides friendly
9
+ # accessors to its component services and provides a handy method to dump
10
+ # information about the device.
11
+ #
12
+ # http://www.upnp.org/standardizeddcps/igd.asp
13
+
14
+ class UPnP::Control::Device::InternetGatewayDevice < UPnP::Control::Device
15
+
16
+ ##
17
+ # The version of UPnP-IGD you are using
18
+
19
+ VERSION = '1.0.0'
20
+
21
+ ##
22
+ # Version 1 URN for InternetGatewayDevice
23
+
24
+ URN_1 = [UPnP::DEVICE_SCHEMA_PREFIX, name.split(':').last, 1].join ':'
25
+
26
+ ##
27
+ # Prints a summary of this gateway devices status to $stdout
28
+
29
+ def print_info
30
+ puts "Gateway at #{presentation_url || url}"
31
+
32
+ status, last_error, uptime = wic.GetStatusInfo
33
+
34
+ up_at = (Time.now - uptime).strftime "%Y-%m-%d %H:%M:%S"
35
+ puts "#{status}, up since #{up_at} (#{uptime} seconds)"
36
+
37
+ case status
38
+ when 'Connected', 'PendingDisconnect' then
39
+ connection_type, = wic.GetConnectionTypeInfo
40
+ puts "Connection type: #{connection_type}"
41
+
42
+ _, upstream, downstream, = wcic.GetCommonLinkProperties
43
+ puts "#{upstream / 1024} Kb/s up, #{downstream / 1024} Kb/s down"
44
+
45
+ external_ip = wic.GetExternalIPAddress
46
+ puts "External IP address: #{external_ip}"
47
+
48
+ port_mappings = wic.port_mappings
49
+
50
+ index_length = port_mappings.length.to_s.length
51
+
52
+ e_host_length = port_mappings.map { |port| port[0].length }.max
53
+ e_host_length = 1 if e_host_length.zero?
54
+
55
+ i_host_length = port_mappings.map { |port| port[4].length }.max
56
+
57
+ puts
58
+ puts "Port mappings:"
59
+ port_mappings.each_with_index do |port, i|
60
+ e_host, e_port, proto, i_port, i_host, enabled, descr, duration = port
61
+ e_host = '*' if e_host.empty?
62
+
63
+ puts "%*d %s %*s:%-5d -> %*s:%-5d \"%s\"" % [
64
+ index_length, i,
65
+ proto,
66
+ e_host_length, e_host, e_port,
67
+ i_host_length, i_host, i_port,
68
+ descr
69
+ ]
70
+ end
71
+ end
72
+
73
+ puts
74
+ end
75
+
76
+ ##
77
+ # An accessor for the Layer3Forwarding service
78
+
79
+ def layer_3_forwarding
80
+ @l3f ||= services.find do |service|
81
+ service.type == UPnP::Control::Service::Layer3Forwarding::URN_1
82
+ end
83
+
84
+ @l3f
85
+ end
86
+
87
+ ##
88
+ # An accessor for the Layer3Forwarding service
89
+
90
+ alias l3f layer_3_forwarding
91
+
92
+ ##
93
+ # An accessor for the WANCommonInterfaceConfig service
94
+
95
+ def wan_common_interface_config
96
+ @wcic ||= services.find do |service|
97
+ UPnP::Control::Service::WANCommonInterfaceConfig === service
98
+ end
99
+
100
+ @wcic
101
+ end
102
+
103
+ ##
104
+ # An accessor for the WANCommonInterfaceConfig service
105
+
106
+ alias wcic wan_common_interface_config
107
+
108
+ ##
109
+ # An accessor for the WANIPConnection service
110
+
111
+ def wan_ip_connection
112
+ @wip ||= services.find do |service|
113
+ UPnP::Control::Service::WANIPConnection === service
114
+ end
115
+
116
+ @wip
117
+ end
118
+
119
+ ##
120
+ # An accessor for the WANIPConnection service
121
+
122
+ alias wic wan_ip_connection
123
+
124
+ end
125
+
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'UPnP/control/service'
3
+
4
+ ##
5
+ # The UPnP Layer 3 Forwarding service models layer-3 packet forwarding
6
+ # services for a WANDevice.
7
+
8
+ class UPnP::Control::Service::Layer3Forwarding < UPnP::Control::Service
9
+
10
+ ##
11
+ # Version 1 URN for the Layer3Forwarding service
12
+
13
+ URN_1 = [UPnP::SERVICE_SCHEMA_PREFIX, name.split(':').last, 1].join ':'
14
+
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'UPnP/control/service'
3
+
4
+ ##
5
+ # A UPnP WAN Common Interface Config service models the physical layer
6
+ # properties of a WAN interface on an InternetGatewayDevice.
7
+
8
+ class UPnP::Control::Service::WANCommonInterfaceConfig < UPnP::Control::Service
9
+
10
+ ##
11
+ # Version 1 URN for the WANCommonInterfaceConfig service
12
+
13
+ URN_1 = [UPnP::SERVICE_SCHEMA_PREFIX, name.split(':').last, 1].join ':'
14
+
15
+ end
16
+
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'UPnP/control/service'
3
+
4
+ ##
5
+ # The UPnP WAN IP Connection service.
6
+ #
7
+ # This service is used to configure and control IP connections on the WAN
8
+ # device of an InternetGatewayDevice.
9
+
10
+ class UPnP::Control::Service::WANIPConnection < UPnP::Control::Service
11
+
12
+ ##
13
+ # Version 1 URN for the WANIPConnection
14
+
15
+ URN_1 = [UPnP::SERVICE_SCHEMA_PREFIX, name.split(':').last, 1].join ':'
16
+
17
+ ##
18
+ # Collects all the port mappings via GetGenericPortMappingEntry and returns
19
+ # an Array containing each response.
20
+
21
+ def port_mappings
22
+ port_mappings = []
23
+ i = 0
24
+
25
+ loop do
26
+ port_mappings << GetGenericPortMappingEntry(i)
27
+ i += 1
28
+ end
29
+ rescue UPnP::Control::Service::UPnPError => e
30
+ raise unless e.code == 713
31
+ port_mappings
32
+ end
33
+
34
+ end
35
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: UPnP-IGD
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Hodel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
14
+ YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
15
+ ZXQwHhcNMDcxMjIxMDIwNDE0WhcNMDgxMjIwMDIwNDE0WjBBMRAwDgYDVQQDDAdk
16
+ cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
17
+ FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
18
+ LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
19
+ U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
20
+ Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
21
+ mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
22
+ g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
23
+ sCANiQ8BAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
24
+ BBS5k4Z75VSpdM0AclG2UvzFA/VW5DANBgkqhkiG9w0BAQUFAAOCAQEAHagT4lfX
25
+ kP/hDaiwGct7XPuVGbrOsKRVD59FF5kETBxEc9UQ1clKWngf8JoVuEoKD774dW19
26
+ bU0GOVWO+J6FMmT/Cp7nuFJ79egMf/gy4gfUfQMuvfcr6DvZUPIs9P/TlK59iMYF
27
+ DIOQ3DxdF3rMzztNUCizN4taVscEsjCcgW6WkUJnGdqlu3OHWpQxZBJkBTjPCoc6
28
+ UW6on70SFPmAy/5Cq0OJNGEWBfgD9q7rrs/X8GGwUWqXb85RXnUVi/P8Up75E0ag
29
+ 14jEc90kN+C7oI/AGCBN0j6JnEtYIEJZibjjDJTSMWlUKKkj30kq7hlUC2CepJ4v
30
+ x52qPcexcYZR7w==
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2008-06-29 00:00:00 -07:00
34
+ default_executable:
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: hoe
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.5.3
45
+ version:
46
+ description: A UPnP extension for Internet Gateway Devices
47
+ email:
48
+ - drbrain@segment7.net
49
+ executables:
50
+ - upnp_igd
51
+ extensions: []
52
+
53
+ extra_rdoc_files:
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.txt
57
+ files:
58
+ - History.txt
59
+ - Manifest.txt
60
+ - README.txt
61
+ - Rakefile
62
+ - bin/upnp_igd
63
+ - lib/UPnP/control/device/internet_gateway_device.rb
64
+ - lib/UPnP/control/service/layer_3_forwarding.rb
65
+ - lib/UPnP/control/service/wan_common_interface_config.rb
66
+ - lib/UPnP/control/service/wan_ip_connection.rb
67
+ has_rdoc: true
68
+ homepage: http://seattlerb.org/UPnP-IGD
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --main
72
+ - README.txt
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: seattlerb
90
+ rubygems_version: 1.2.0
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: A UPnP extension for Internet Gateway Devices
94
+ test_files: []
95
+
Binary file