more fixes

This commit is contained in:
Jack Robison 2018-08-01 17:57:27 -04:00
parent 5f784a7ce8
commit 2c8b018ebf
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
5 changed files with 24 additions and 14 deletions

View file

@ -1,4 +1,4 @@
__version__ = "0.0.1a3" __version__ = "0.0.1a4"
__name__ = "txupnp" __name__ = "txupnp"
__author__ = "Jack Robison" __author__ = "Jack Robison"
__maintainer__ = "Jack Robison" __maintainer__ = "Jack Robison"

View file

@ -1,4 +1,3 @@
import sys
import argparse import argparse
import logging import logging
from twisted.internet import reactor, defer from twisted.internet import reactor, defer
@ -20,11 +19,13 @@ def get_external_ip(u, *_):
@defer.inlineCallbacks @defer.inlineCallbacks
def list_mappings(u, *_): def list_mappings(u, *_):
print(u.get_debug_info(include_gateway_xml=True))
redirects = yield u.get_redirects() redirects = yield u.get_redirects()
print("found {} redirects".format(len(redirects))) ext_ip = yield u.get_external_ip()
for redirect in redirects: for (ext_host, ext_port, proto, int_port, int_host, enabled, desc, lease) in redirects:
print("\t", redirect) 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 = { cli_commands = {

View file

@ -90,13 +90,14 @@ class SSDPProtocol(DatagramProtocol):
return return
if packet._packet_type == packet._OK: 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) 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): if packet.st not in map(lambda p: p['st'], self.devices):
self.devices.append(packet.as_dict()) self.devices.append(packet.as_dict())
log.debug("%i device%s so far", len(self.devices), "" if len(self.devices) < 2 else "s") log.debug("%i device%s so far", len(self.devices), "" if len(self.devices) < 2 else "s")
if address[0] in self.discover_callbacks: if address[0] in self.discover_callbacks:
self._sem.run(self.discover_callbacks[address[0]][0], packet) 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): class SSDPFactory(object):

View file

@ -50,6 +50,14 @@ class SSDPDatagram(object):
'man', 'man',
'mx', 'mx',
], ],
_NOTIFY: [
'host',
'location',
'nt',
'nts',
'server',
'usn',
],
_OK: [ _OK: [
'cache_control', 'cache_control',
# 'date', # 'date',

View file

@ -73,7 +73,7 @@ class UPnP(object):
def add_port_mapping(self, external_port, protocol, internal_port, lan_address, description, lease_duration): def add_port_mapping(self, external_port, protocol, internal_port, lan_address, description, lease_duration):
return self.commands.AddPortMapping( return self.commands.AddPortMapping(
NewRemoteHost=None, NewExternalPort=external_port, NewProtocol=protocol, NewRemoteHost="", NewExternalPort=external_port, NewProtocol=protocol,
NewInternalPort=internal_port, NewInternalClient=lan_address, NewInternalPort=internal_port, NewInternalClient=lan_address,
NewEnabled=1, NewPortMappingDescription=description, NewEnabled=1, NewPortMappingDescription=description,
NewLeaseDuration=lease_duration NewLeaseDuration=lease_duration