예제 #1
0
    def create_options():
        """A class factory which parses command line options and returns an options instance"""
        parser = OptionParser()
        parser.add_option('-i', '--iface', dest='iface', default='mon0',
                          help='Interface to bind to')
        parser.add_option('-t', '--timeout', dest='timeout', default=5, type='int',
                          help='Timeout for the channel hop')
        parser.add_option('-c', '--channel', dest='channel', default=-1, type='int',
                          help='Channel to bind to')
        parser.add_option('--max-channel', dest='max_channel', default=-1, type='int',
                          help='Maximum channel number')
        options, _ = parser.parse_args()

        dump_options = WifiDumpOptions()
        dump_options.iface = options.iface
        dump_options.we = WirelessExtension(dump_options.iface)
        dump_options.timeout = options.timeout
        dump_options.channel = options.channel
        dump_options.channel_hop = (-1 == options.channel)
        dump_options.max_channel = options.max_channel
        if -1 == dump_options.max_channel:
            try:
                dump_options.max_channel = dump_options.we.get_max_channel()
                Printer.verbose('CHAN: max_channel[{0}]'.format(dump_options.max_channel), verbose_level=1)
            except Exception, e:
                Printer.exception(e)
                raise
예제 #2
0
def scapy_layers_dot11_Dot11_rsn(self):
    """Return the payload of the RSN Dot11Elt as a Dot11EltRSN"""
    elt = self.find_elt_by_id(48)
    if elt:
        try:
            return Dot11EltRSN(str(elt))
        except Exception, e:
            Printer.error('Bad Dot11EltRSN got[{0:s}]'.format(elt.info))
            Printer.exception(e)
예제 #3
0
def scapy_layers_dot11_Dot11_channel(self):
    """Return the payload of the channel Dot11Elt if it exists"""
    elt = self.find_elt_by_id(3)
    if elt:
        try:
            return int(ord(elt.info))
        except Exception, e:
            Printer.error('Bad Dot11Elt channel got[{0:s}]'.format(elt.info))
            Printer.exception(e)
예제 #4
0
def scapy_layers_dot11_Dot11_rates(self, id=1):
    """Return the payload of the rates Dot11Elt if it exists"""
    elt = self.find_elt_by_id(id)
    if elt:
        try:
            return Dot11EltRates(str(elt)).rates
        except Exception, e:
            Printer.error('Bad Dot11EltRates got[{0:s}]'.format(elt.info))
            Printer.exception(e)
예제 #5
0
def scapy_layers_dot11_Dot11_rsn(self):
    """Return the payload of the RSN Dot11Elt as a Dot11EltRSN"""
    elt = self.find_elt_by_id(48)
    if elt:
        try:
            return Dot11EltRSN(str(elt))
        except Exception, e:
            Printer.error("Bad Dot11EltRSN got[{0:s}]".format(elt.info))
            Printer.exception(e)
예제 #6
0
def scapy_layers_dot11_Dot11_channel(self):
    """Return the payload of the channel Dot11Elt if it exists"""
    elt = self.find_elt_by_id(3)
    if elt:
        try:
            return int(ord(elt.info))
        except Exception, e:
            Printer.error("Bad Dot11Elt channel got[{0:s}]".format(elt.info))
            Printer.exception(e)
예제 #7
0
def scapy_layers_dot11_Dot11_rates(self, id=1):
    """Return the payload of the rates Dot11Elt if it exists"""
    elt = self.find_elt_by_id(id)
    if elt:
        try:
            return Dot11EltRates(str(elt)).rates
        except Exception, e:
            Printer.error("Bad Dot11EltRates got[{0:s}]".format(elt.info))
            Printer.exception(e)
예제 #8
0
def main():

    try:
        options = WifiDumpOptions.create_options()
        scanner = WifiScanner(options)
        scanner.attach(ConsolePrinter())

        try:
            scanner.scan()
        except Exception, e:
            Printer.exception(e)

    except Exception, e:
        sys.stderr.write(repr(e))
        traceback.print_exc(file=sys.stderr)
예제 #9
0
    def scan(self):
        while True:
            try:
                
                if not self.do_scan():
                    break

            # Exit the scan on a keyboard break
            except KeyboardInterrupt:
                break

            # Curses generates system interupt exception (EINTR) when the window is resized
            except Exception, e:
                if e.args and e.args[0] == errno.EINTR:
                    pass
                else:
                    Printer.exception(e)
                    raise
예제 #10
0
    def apply_filter(self, packet):
        try:
            # Verify the RadioTap header, scanner, and WE all match
            # if packet.haslayer(RadioTap) and not self.options.input_file:
                # assert (self.options.channel == packet[RadioTap].Channel), 'got[{0}] expect[{1}]'.format(packet[RadioTap].Channel, self.options.channel)

                # channel = self.options.we.get_channel()
                # assert (self.options.channel == channel), 'got[{0}] expected[{1}]'.format(channel, self.options.channel)

            # Track AP and STA
            if packet.haslayer(Dot11):
                self.notify(packet)
                return True

            # That's unexpected.  print for debugging
            else:
                Printer.error(packet.show())
        except Exception, exc:
            Printer.exception(exc)