示例#1
0
    def GetDeviceDetails(self, sData, tSenderAddr):
        oRet = QueryDict()
        oRet.bFound = False
        oRet.sFoundIP = ""
        oRet.uFoundPort = ""
        oRet.uFoundModel = ""
        oRet.uFoundIdentifier = ""
        oRet.uFoundCategory = ""
        oRet.sData = ""

        if PY2:
            uResponse = sData[16:]
        else:
            uResponse = ToUnicode(sData)[16:]

        if uResponse.find('ECN') != -1:
            info = re.match(self.rMatch, uResponse.strip(),
                            re.VERBOSE).groupdict()
            uResponse = uResponse[10:]
            oRet.sFoundIP = tSenderAddr[0]
            oRet.uFoundPort = ToUnicode(info['iscp_port'])
            oRet.uFoundModel = info['model_name']
            oRet.uFoundIdentifier = info['identifier']
            oRet.uFoundCategory = ToUnicode(info['device_category'])
            oRet.sData = uResponse
            oRet.bFound = True
        return oRet
示例#2
0
 def GetDeviceDetails(self,sData,tSenderAddr):
     oRet                     = QueryDict()
     oRet.sFoundIP            = tSenderAddr[0]
     oRet.uFoundPort          = tSenderAddr[1]
     oRet.bFound              = True
     oRet.sData               = sData
     oRet.uIPVersion          = self.uIPVersion
     return oRet
示例#3
0
    def GetDeviceDetails(self, sData, tSenderAddr):

        oRet = QueryDict()
        oRet.sFoundIP = tSenderAddr[0]
        oRet.sData = sData
        oRet.uFoundName = sData[0:8].decode('utf-8')
        oRet.uFoundSerial = sData[8:18].decode('utf-8')
        oRet.uFoundHostName = socket.gethostbyaddr(oRet.sFoundIP)[0]
        oRet.uIPVersion = u"IPv4"

        Logger.info(u'Bingo: Dicovered device %s:%s:%s at %s' %
                    (oRet.uFoundName, oRet.uFoundHostName, oRet.uFoundSerial,
                     oRet.sFoundIP))

        return oRet
示例#4
0
    def GetDeviceDetails(self, sData, tSenderAddr):
        oRet = QueryDict()
        oRet.uFoundManufacturer = u""
        oRet.uFoundModel = u""
        oRet.uFoundFriendlyName = u""
        oRet.uFoundServiceType = u""
        oRet.sFoundIP = tSenderAddr[0]
        oRet.uIPVersion = self.uIPVersion[:4]
        oRet.bFound = False
        oRet.sData = sData
        oRet.uResult = u""
        oRet.uFoundHostName = u""
        uUrl = u""

        if not PY2:
            oRet.sData = ToUnicode(oRet.sData)

        if oRet.uIPVersion == "IPv6":
            oRet.sFoundIP = "[%s}" % oRet.sFoundIP

        # if we got a response
        if '200 OK' in oRet.sData:
            aData = oRet.sData.splitlines()
            uFoundServiceType = ""

            # The location field as part of DIAL specification and contains a link to an XML with further device infos
            for uLine in aData:
                if uLine.upper().startswith('LOCATION:'):
                    uUrl = uLine[9:].strip()
                if uLine.startswith('ST'):
                    oRet.uFoundServiceType = uLine[3:].strip()
                    uFoundServiceType = uFoundServiceType

            Logger.debug(u'Trying to get device details from  %s' % uUrl)

            try:

                self.oUrlRequest = UrlRequest(uUrl,
                                              method="GET",
                                              req_body='',
                                              req_headers={
                                                  "Connection": "Keep-Alive",
                                                  "Accept-Encoding": "gzip"
                                              },
                                              timeout=self.fTimeOut,
                                              on_error=self.OnError)
                self.NewWait(0.05)
                iStatusCode = self.oUrlRequest.resp_status

                if iStatusCode == 200 and "device" in self.oUrlRequest.result:
                    oRet.uResult = RemoveURN(self.oUrlRequest.result)
                    oNode = ElementTree(fromstring(oRet.uResult))
                    oNode = oNode.find("device")
                    oRet.uFoundManufacturer = oNode.find("manufacturer").text
                    oRet.uFoundModel = oNode.find("modelName").text

                    try:
                        oRet.uFoundFriendlyName = oNode.find(
                            "friendlyName").text
                    except Exception as e:
                        pass
                    oRet.bFound = True
                    Logger.debug(u'Found Device %s:%s:%s (%s)' %
                                 (oRet.uFoundManufacturer, oRet.uFoundModel,
                                  oRet.uFoundFriendlyName, oRet.sFoundIP))
            except Exception as e:
                LogError("Can''t get device details. skipping device: " + uUrl,
                         e)

        return oRet