NAME
Net::UPnP::GW::Gateway - Perl extension for UPnP.
SYNOPSIS
use Net::UPnP::ControlPoint;
use Net::UPnP::GW::Gateway;
my $obj = Net::UPnP::ControlPoint->new();
@dev_list = ();
while (@dev_list <= 0 || $retry_cnt > 5) {
# @dev_list = $obj->search(st =>'urn:schemas-upnp-org:device:InternetGatewayDevice:1', mx => 10);
@dev_list = $obj->search(st =>'upnp:rootdevice', mx => 3);
$retry_cnt++;
}
$devNum= 0;
foreach $dev (@dev_list) {
my $device_type = $dev->getdevicetype();
if ($device_type ne 'urn:schemas-upnp-org:device:InternetGatewayDevice:1') {
next;
}
print "[$devNum] : " . $dev->getfriendlyname() . "\n";
my $gwdev = Net::UPnP::GW::Gateway->new();
$gwdev->setdevice($dev);
# WANIPConnection, or WANPPPConnection on dial-up routers
next unless $gwdev->getconnectionservice();
print "\tExternalIPAddress = " . $gwdev->getexternalipaddress() . "\n";
print "\tPortMappingNumberOfEntries = " . $gwdev->getportmappingnumberofentries() . "\n";
@port_mapping = $gwdev->getportmappingentries();
$port_num = 0;
foreach $port_entry (@port_mapping) {
$port_map_name = $port_entry->{'NewPortMappingDescription'};
if (length($port_map_name) <= 0) {
$port_map_name = "(No name)";
}
print " [$port_num] : $port_map_name\n";
foreach $name ( keys %{$port_entry} ) {
print " $name = $port_entry->{$name}\n";
}
$port_num++;
}
}
DESCRIPTION
The package is an extension UPnP/GW.
METHODS
- new - create new Net::UPnP::GW::Gateway.
-
$mservier = Net::UPnP::GW::Gateway();Creates a new object. Read `perldoc perlboot` if you don't understand that.
The new object is not associated with any UPnP devices. Please use setdevice() to set the device.
$gw = Net::UPnP::GW::Gateway->new(connection_service_type => $type);By default the gateway uses the
WANIPConnection:1service and falls back toWANPPPConnection:1, which dial-up (PPPoE/PPPoA) routers often provide instead. Passconnection_service_typeto use one service type only. - setconnectionservicetype - select the WAN connection service type.
-
$gw->setconnectionservicetype('urn:schemas-upnp-org:service:WANPPPConnection:1');Use only the given service type. Pass
undefto restore the default (WANIPConnection, then WANPPPConnection). - getconnectionservice - get the WAN connection service.
-
$service = $gw->getconnectionservice();Returns the Net::UPnP::Service used for the external IP address and port mapping methods, or
undefif the device has none. - getconnectionservicetype - get the WAN connection service type.
-
$type = $gw->getconnectionservicetype();Returns the service type of getconnectionservice(), or an empty string.
- getstatusinfo - get the connection status.
-
$info = $gw->getstatusinfo();Returns a hash reference with
ConnectionStatus,LastConnectionErrorandUptime, orundefon failure. - getconnectiontypeinfo - get the connection type.
-
$info = $gw->getconnectiontypeinfo();Returns a hash reference with
ConnectionTypeandPossibleConnectionTypes, orundefon failure. - getlinklayermaxbitrates - get the link layer bit rates.
-
$info = $gw->getlinklayermaxbitrates();Returns a hash reference with
UpstreamMaxBitRateandDownstreamMaxBitRate. This action exists only in WANPPPConnection, soundefis returned when the gateway uses WANIPConnection. =item setdevice - set a UPnP devices$gw->setdevice($dev);Set a device to the object.
- getexternalipaddress - External IP address
-
$gw->getexternalipaddress();Get the external IP address.
- getportmappingnumberofentries - PortMappingNumberOfEntries
-
$gw->getportmappingnumberofentries();Get the number of the port mapping entries.
- getportmappingentries - PortMappingEntry
-
$gw->getportmappingentries();Get the port mapping entries.
- addportmapping - add new port mapping.
-
$result = gw->addportmapping( NewRemoteHost # '', NewExternalPort # '', NewProtocol # '', NewInternalPort # '', NewInternalClient # '', NewEnabled #1, NewPortMappingDescription # '', NewLeaseDuration # 0);Add a new specified port mapping.
- deleteportmapping - delete a port mapping.
-
$result = gw->deleteportmapping( NewRemoteHost # '', NewExternalPort # '', NewProtocol # '');Delete the specified port mapping.
- gettotalbytesreceived - Total received bytes.
-
$gw->gettotalbytesreceived();Get the total received bytes. The misspelled name
gettotalbytesrecievedis kept as an alias for backward compatibility.
AUTHOR
Satoshi Konno skonno@cybergarage.org
CyberGarage http://www.cybergarage.org
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Satoshi Konno
It may be used, redistributed, and/or modified under the terms of BSD License.