Example #1
0
    def test_InitalizeSCPD(self):
        results = Discover.discover(retries=2)
        self.assertTrue(len(results) > 0, "No UPnP host found at all.")

        # setup proxies for discovery call
        proxies = {}
        if defaults.test_httpsProxy:
            proxies = {"https": defaults.test_httpsProxy}

        if defaults.test_httpProxy:
            proxies = {"http": defaults.test_httpProxy}

        # pick the best device in the result list for later loads
        bestResult = None
        for result in results:
            if Discover.rateServiceTypeInResult(
                    result) > Discover.rateServiceTypeInResult(bestResult):
                bestResult = result

        # find the device again
        result = Discover.discoverParticularHost(bestResult.locationHost,
                                                 proxies=proxies,
                                                 retries=1)
        self.assertTrue(result is not None,
                        "Failed to discover: " + bestResult.locationHost)

        box = DeviceTR64(result.locationHost, result.locationPort,
                         result.locationProtocol)
        box.username = defaults.test_user
        box.password = defaults.test_pw
        box.httpProxy = defaults.test_httpProxy
        box.httpsProxy = defaults.test_httpsProxy

        # the discovery result contains the right URL to initialize device definitions
        box.loadDeviceDefinitions(result.location)
        # load the actions
        box.loadSCPD()

        # the following calls can fail if the device found has not all the definitions needed
        #
        self.assertTrue(
            len(box.deviceServiceDefinitions.keys()) > 0,
            "Host: " + result.locationHost + " Result used: " + str(result))
        self.assertTrue(
            len(box.deviceInformations.keys()) > 0,
            "Host: " + result.locationHost + " Result used: " + str(result))
        self.assertTrue(
            len(box.deviceSCPD.keys()) > 0,
            "Host: " + result.locationHost + " Result used: " + str(result))
Example #2
0
    def test_InitalizeSCPD(self):
        results = Discover.discover(retries=2)
        self.assertTrue(len(results) > 0, "No UPnP host found at all.")

        # setup proxies for discovery call
        proxies = {}
        if defaults.test_httpsProxy:
            proxies = {"https": defaults.test_httpsProxy}

        if defaults.test_httpProxy:
            proxies = {"http": defaults.test_httpProxy}

        # pick the best device in the result list for later loads
        bestResult = None
        for result in results:
            if Discover.rateServiceTypeInResult(result) > Discover.rateServiceTypeInResult(bestResult):
                bestResult = result

        # find the device again
        result = Discover.discoverParticularHost(bestResult.locationHost, proxies=proxies, retries=1)
        self.assertTrue(result is not None, "Failed to discover: " + bestResult.locationHost)

        box = DeviceTR64(result.locationHost, result.locationPort, result.locationProtocol)
        box.username = defaults.test_user
        box.password = defaults.test_pw
        box.httpProxy = defaults.test_httpProxy
        box.httpsProxy = defaults.test_httpsProxy

        # the discovery result contains the right URL to initialize device definitions
        box.loadDeviceDefinitions(result.location)
        # load the actions
        box.loadSCPD()

        # the following calls can fail if the device found has not all the definitions needed
        #
        self.assertTrue(len(box.deviceServiceDefinitions.keys()) > 0, "Host: " + result.locationHost +
                        " Result used: " + str(result))
        self.assertTrue(len(box.deviceInformations.keys()) > 0, "Host: " + result.locationHost +
                        " Result used: " + str(result))
        self.assertTrue(len(box.deviceSCPD.keys()) > 0, "Host: " + result.locationHost +
                        " Result used: " + str(result))
Example #3
0
 def test_discover(self):
     results = Discover.discover(retries=1)
     self.assertTrue(len(results) > 0)
if use_httpProxy:
    proxies = {"http": use_httpProxy}

print("Start discovery.")

# add some more services to search for, just making sure every device answers
services = [
    "ssdp:all", "urn:schemas-any-com:service:Any:1",
    "urn:dslforum-org:device:InternetGatewayDevice:1",
    "urn:dslforum-org:device:LANDevice:1",
    "urn:dslforum-org:service:Layer3Forwarding:1",
    "urn:schemas-upnp-org:device:basic:1"
]

# start a broad dicovery
results = Discover.discover(service=services)

hostResults = {}

for result in results:
    if result.locationHost not in hostResults.keys():
        hostResults[result.locationHost] = []

    # remember all results for a dedicated host, add rating for later sorting
    hostResults[result.locationHost].append({
        "sortKey":
        Discover.rateServiceTypeInResult(result),
        "result":
        result
    })
Example #5
0
use_httpProxy = args.http
use_httpsProxy = args.https

#######################################################################################################################

# setup proxies for discovery call
proxies = {}
if use_httpsProxy:
    proxies = {"https": use_httpsProxy}

if use_httpProxy:
    proxies = {"http": use_httpProxy}

# get TR64 multicast result for the given host to get XML definition url
result = Discover.discoverParticularHost(use_host,
                                         proxies=proxies,
                                         timeout=use_timeout)

if not result:
    raise ValueError("Could not discover given host: " + use_host)

# get instance of device
box = DeviceTR64.createFromURL(result.location)
box.username = use_user
box.password = use_pw
box.httpProxy = use_httpProxy
box.httpsProxy = use_httpsProxy

# the discovery result contains the right URL to initialize device definitions
box.loadDeviceDefinitions(result.location, timeout=use_timeout)
# load the actions
use_pw = args.password
use_httpProxy = args.http
use_httpsProxy = args.https

#######################################################################################################################

# setup proxies for discovery call
proxies = {}
if use_httpsProxy:
    proxies = {"https": use_httpsProxy}

if use_httpProxy:
    proxies = {"http": use_httpProxy}

# get TR64 multicast result for the given host to get XML definition url
result = Discover.discoverParticularHost(use_host, proxies=proxies, timeout=use_timeout)

if not result:
    raise ValueError("Could not discover given host: " + use_host)

# get instance of device
box = DeviceTR64.createFromURL(result.location)
box.username = use_user
box.password = use_pw
box.httpProxy = use_httpProxy
box.httpsProxy = use_httpsProxy

# the discovery result contains the right URL to initialize device definitions
box.loadDeviceDefinitions(result.location, timeout=use_timeout)
# load the actions
box.loadSCPD(timeout=use_timeout, ignoreFailures=True)
    proxies = {"http": use_httpProxy}

print("Start discovery.")

# add some more services to search for, just making sure every device answers
services = [
    "ssdp:all",
    "urn:schemas-any-com:service:Any:1",
    "urn:dslforum-org:device:InternetGatewayDevice:1",
    "urn:dslforum-org:device:LANDevice:1",
    "urn:dslforum-org:service:Layer3Forwarding:1",
    "urn:schemas-upnp-org:device:basic:1",
]

# start a broad dicovery
results = Discover.discover(service=services)

hostResults = {}

for result in results:
    if result.locationHost not in hostResults.keys():
        hostResults[result.locationHost] = []

    # remember all results for a dedicated host, add rating for later sorting
    hostResults[result.locationHost].append({"sortKey": Discover.rateServiceTypeInResult(result), "result": result})

output = {}

print("Amount of hosts found: " + str(len(hostResults.keys())))
print("Processing: ")
Example #8
0
 def test_discover(self):
     results = Discover.discover(retries=1)
     self.assertTrue(len(results) > 0)