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))
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))
output[host] = {} output[host]["services"] = {} # noinspection PyBroadException try: output[host]["hostname"] = socket.gethostbyaddr(host)[0] print("Host: " + output[host]["hostname"]) except: print("Host: " + host) try: # get TR64 multicast result for the given host to get XML definition url result = Discover.discoverParticularHost( host, service=sortedResults[0]["result"].service, retries=1, proxies=proxies, timeout=use_timeout) except (requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError) as e: # could not download the gile print("Host " + host + " failed: " + str(e)) result = None if result is not None: hostResults[host].append({ "sortKey": Discover.rateServiceTypeInResult(result), "result": result })
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)
sortedResults = sorted(hostResults[host], key=lambda sortit: sortit["sortKey"], reverse=True) output[host] = {} output[host]["services"] = {} # noinspection PyBroadException try: output[host]["hostname"] = socket.gethostbyaddr(host)[0] print("Host: " + output[host]["hostname"]) except: print("Host: " + host) try: # get TR64 multicast result for the given host to get XML definition url result = Discover.discoverParticularHost( host, service=sortedResults[0]["result"].service, retries=1, proxies=proxies, timeout=use_timeout ) except (requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError) as e: # could not download the gile print("Host " + host + " failed: " + str(e)) result = None if result is not None: hostResults[host].append({"sortKey": Discover.rateServiceTypeInResult(result), "result": result}) # resort making sure we start with the important one first sortedResults = sorted(hostResults[host], key=lambda sortit: sortit["sortKey"], reverse=True) # load all xml file definitions for this host loadedXMLFile = [] for sResult in sortedResults: