Class: UPnP::Control::Device::InternetGatewayDevice

Inherits:
UPnP::Control::Device
  • Object
show all
Defined in:
lib/UPnP/control/device/internet_gateway_device.rb

Overview

A UPnP Internet Gateway Device control point that provides friendly accessors to its component services and provides a handy method to dump information about the device.

www.upnp.org/standardizeddcps/igd.asp

Constant Summary collapse

VERSION =

The version of UPnP-IGD you are using

'1.0.0'
URN_1 =

Version 1 URN for InternetGatewayDevice

[UPnP::DEVICE_SCHEMA_PREFIX, name.split(':').last, 1].join ':'

Instance Method Summary collapse

Instance Method Details

#layer_3_forwardingObject Also known as: l3f

An accessor for the Layer3Forwarding service



79
80
81
82
83
84
85
# File 'lib/UPnP/control/device/internet_gateway_device.rb', line 79

def layer_3_forwarding
  @l3f ||= services.find do |service|
    service.type == UPnP::Control::Service::Layer3Forwarding::URN_1
  end

  @l3f
end

Prints a summary of this gateway devices status to $stdout



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/UPnP/control/device/internet_gateway_device.rb', line 29

def print_info
  puts "Gateway at #{presentation_url || url}"

  status, last_error, uptime = wic.GetStatusInfo

  up_at = (Time.now - uptime).strftime "%Y-%m-%d %H:%M:%S"
  puts "#{status}, up since #{up_at} (#{uptime} seconds)"

  case status
  when 'Connected', 'PendingDisconnect' then
    connection_type, = wic.GetConnectionTypeInfo
    puts "Connection type: #{connection_type}"

    _, upstream, downstream, = wcic.GetCommonLinkProperties
    puts "#{upstream / 1024} Kb/s up, #{downstream / 1024} Kb/s down"

    external_ip = wic.GetExternalIPAddress
    puts "External IP address: #{external_ip}"

    port_mappings = wic.port_mappings

    index_length = port_mappings.length.to_s.length

    e_host_length = port_mappings.map { |port| port[0].length }.max
    e_host_length = 1 if e_host_length.zero?

    i_host_length = port_mappings.map { |port| port[4].length }.max

    puts
    puts "Port mappings:"
    port_mappings.each_with_index do |port, i|
      e_host, e_port, proto, i_port, i_host, enabled, descr, duration = port
      e_host = '*' if e_host.empty?

      puts "%*d %s %*s:%-5d -> %*s:%-5d \"%s\"" % [
        index_length, i,
        proto,
        e_host_length, e_host, e_port,
        i_host_length, i_host, i_port,
        descr
      ]
    end
  end

  puts
end

#wan_common_interface_configObject Also known as: wcic

An accessor for the WANCommonInterfaceConfig service



95
96
97
98
99
100
101
# File 'lib/UPnP/control/device/internet_gateway_device.rb', line 95

def wan_common_interface_config
  @wcic ||= services.find do |service|
    UPnP::Control::Service::WANCommonInterfaceConfig === service
  end

  @wcic
end

#wan_ip_connectionObject Also known as: wic

An accessor for the WANIPConnection service



111
112
113
114
115
116
117
# File 'lib/UPnP/control/device/internet_gateway_device.rb', line 111

def wan_ip_connection
  @wip ||= services.find do |service|
    UPnP::Control::Service::WANIPConnection === service
  end

  @wip
end