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"
|
__name__ = "txupnp"
|
||||||
__author__ = "Jack Robison"
|
__author__ = "Jack Robison"
|
||||||
__maintainer__ = "Jack Robison"
|
__maintainer__ = "Jack Robison"
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
|
@ -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:
|
if packet.st not in map(lambda p: p['st'], self.devices):
|
||||||
log.debug("%s:%i notified us of a service type: %s", address[0], address[1], packet.st)
|
self.devices.append(packet.as_dict())
|
||||||
if packet.st not in map(lambda p: p['st'], self.devices):
|
log.debug("%i device%s so far", len(self.devices), "" if len(self.devices) < 2 else "s")
|
||||||
self.devices.append(packet.as_dict())
|
if address[0] in self.discover_callbacks:
|
||||||
log.debug("%i device%s so far", len(self.devices), "" if len(self.devices) < 2 else "s")
|
self._sem.run(self.discover_callbacks[address[0]][0], packet)
|
||||||
if address[0] in self.discover_callbacks:
|
elif packet._packet_type == packet._NOTIFY:
|
||||||
self._sem.run(self.discover_callbacks[address[0]][0], packet)
|
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):
|
||||||
|
|
|
@ -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',
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue