collect.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:captiv8 作者: wraith-wireless 项目源码 文件源码
def _setup(self):
        """ setup radio and tuning thread """
        # set up the radio for collection
        nlsock = None
        try:
            # get a netlink socket for this
            nlsock = nl.nl_socket_alloc()

            # get dev info for dev and it's phy index
            self._dinfo = pyw.devinfo(self._dev,nlsock)
            phy = self._dinfo['card'].phy

            # delete all associated interfaces
            for c,_ in pyw.ifaces(self._dinfo['card'],nlsock): pyw.devdel(c,nlsock)

            # create a new card in monitor mode
            self._card = pyw.phyadd(phy,'cap8','monitor',None,nlsock)
            pyw.up(self._card)

            # determine scannable channels, then go to first channel
            scan = []
            for rf in pyw.devfreqs(self._card,nlsock):
                for chw in channels.CHTYPES:
                    try:
                        pyw.freqset(self._card,rf,chw,nlsock)
                        scan.append((rf, chw))
                    except pyric.error as e:
                        if e.errno != pyric.EINVAL: raise
            assert scan
            pyw.freqset(self._card,scan[0][0],scan[0][1],nlsock)

            # create the tuner & sniffer
            self._pktq = mp.Queue()
            self._tuner = Tuner(self._card,scan)
            self._sniffer = Sniffer(self._pktq,self._card.dev)
        except RuntimeError as e:
            self._teardown()
            raise RuntimeError("Error binding socket {0}".format(e))
        except threading.ThreadError as e:
            self._teardown()
            raise RuntimeError("Unexepected error in the workers {0}".format(e))
        except AssertionError:
            self._teardown()
            raise RuntimeError("No valid scan channels found")
        except nl.error as e:
            self._teardown()
            raise RuntimeError("ERRNO {0} {1}".format(e.errno, e.strerror))
        except pyric.error as e:
            self._teardown() # attempt to restore
            raise RuntimeError("ERRNO {0} {1}".format(e.errno, e.strerror))
        finally:
            nl.nl_socket_free(nlsock)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号