more fixes
This commit is contained in:
parent
5f784a7ce8
commit
2c8b018ebf
5 changed files with 24 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
|||
__version__ = "0.0.1a3"
|
||||
__version__ = "0.0.1a4"
|
||||
__name__ = "txupnp"
|
||||
__author__ = "Jack Robison"
|
||||
__maintainer__ = "Jack Robison"
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -50,6 +50,14 @@ class SSDPDatagram(object):
|
|||
'man',
|
||||
'mx',
|
||||
],
|
||||
_NOTIFY: [
|
||||
'host',
|
||||
'location',
|
||||
'nt',
|
||||
'nts',
|
||||
'server',
|
||||
'usn',
|
||||
],
|
||||
_OK: [
|
||||
'cache_control',
|
||||
# 'date',
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue