diff --git a/txupnp/__init__.py b/txupnp/__init__.py index c377ede..0106af1 100644 --- a/txupnp/__init__.py +++ b/txupnp/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.0.1a3" +__version__ = "0.0.1a4" __name__ = "txupnp" __author__ = "Jack Robison" __maintainer__ = "Jack Robison" diff --git a/txupnp/cli.py b/txupnp/cli.py index a52e72b..3bbfd12 100644 --- a/txupnp/cli.py +++ b/txupnp/cli.py @@ -1,4 +1,3 @@ -import sys import argparse import logging from twisted.internet import reactor, defer @@ -20,11 +19,13 @@ def get_external_ip(u, *_): @defer.inlineCallbacks def list_mappings(u, *_): - print(u.get_debug_info(include_gateway_xml=True)) redirects = yield u.get_redirects() - print("found {} redirects".format(len(redirects))) - for redirect in redirects: - print("\t", redirect) + ext_ip = yield u.get_external_ip() + for (ext_host, ext_port, proto, int_port, int_host, enabled, desc, lease) in redirects: + print("{}:{}/{} --> {}:{} ({}) (expires: {}) - {} ".format( + ext_host or ext_ip, ext_port, proto, int_host, int_port, "enabled" if enabled else "disabled", + "never" if not lease else lease, desc) + ) cli_commands = { diff --git a/txupnp/ssdp.py b/txupnp/ssdp.py index 48f513d..e7f4397 100644 --- a/txupnp/ssdp.py +++ b/txupnp/ssdp.py @@ -90,13 +90,14 @@ class SSDPProtocol(DatagramProtocol): return if packet._packet_type == packet._OK: log.debug("%s:%i replied to our m-search with new xml url: %s", address[0], address[1], packet.location) - else: - log.debug("%s:%i notified us of a service type: %s", address[0], address[1], packet.st) - if packet.st not in map(lambda p: p['st'], self.devices): - self.devices.append(packet.as_dict()) - log.debug("%i device%s so far", len(self.devices), "" if len(self.devices) < 2 else "s") - if address[0] in self.discover_callbacks: - self._sem.run(self.discover_callbacks[address[0]][0], packet) + if packet.st not in map(lambda p: p['st'], self.devices): + self.devices.append(packet.as_dict()) + log.debug("%i device%s so far", len(self.devices), "" if len(self.devices) < 2 else "s") + if address[0] in self.discover_callbacks: + self._sem.run(self.discover_callbacks[address[0]][0], packet) + elif packet._packet_type == packet._NOTIFY: + log.debug("%s:%i sent us a notification (type: %s), url: %s", address[0], address[1], packet.nts, + packet.location) class SSDPFactory(object): diff --git a/txupnp/ssdp_datagram.py b/txupnp/ssdp_datagram.py index ad440ba..dbc8e8f 100644 --- a/txupnp/ssdp_datagram.py +++ b/txupnp/ssdp_datagram.py @@ -50,6 +50,14 @@ class SSDPDatagram(object): 'man', 'mx', ], + _NOTIFY: [ + 'host', + 'location', + 'nt', + 'nts', + 'server', + 'usn', + ], _OK: [ 'cache_control', # 'date', diff --git a/txupnp/upnp.py b/txupnp/upnp.py index 8a8df40..3f6f4f9 100644 --- a/txupnp/upnp.py +++ b/txupnp/upnp.py @@ -73,7 +73,7 @@ class UPnP(object): def add_port_mapping(self, external_port, protocol, internal_port, lan_address, description, lease_duration): return self.commands.AddPortMapping( - NewRemoteHost=None, NewExternalPort=external_port, NewProtocol=protocol, + NewRemoteHost="", NewExternalPort=external_port, NewProtocol=protocol, NewInternalPort=internal_port, NewInternalClient=lan_address, NewEnabled=1, NewPortMappingDescription=description, NewLeaseDuration=lease_duration