示例#1
0
def msg_handler(m, a):
    try:
        e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
                                        nl80211.NL80211_ATTR_MAX, None)
        if nl80211.NL80211_ATTR_WIPHY in attr:
            thiswiphy = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY])
            print("phy#%d" % thiswiphy)
        if nl80211.NL80211_ATTR_IFNAME in attr:
            print("\tinterface %s" %
                  nl.nla_get_string(attr[nl80211.NL80211_ATTR_IFNAME]))
        if nl80211.NL80211_ATTR_IFINDEX in attr:
            print("\tifindex %d" %
                  nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFINDEX]))
        if nl80211.NL80211_ATTR_WDEV in attr:
            print("\twdev 0x%lx" %
                  nl.nla_get_u64(attr[nl80211.NL80211_ATTR_WDEV]))
        if nl80211.NL80211_ATTR_MAC in attr:
            print("\tmac %02x:%02x:%02x:%02x:%02x:%02x" %
                  tuple(nl.nla_data(attr[nl80211.NL80211_ATTR_MAC])))
        if nl80211.NL80211_ATTR_SSID in attr:
            print("\tssid ", nl.nla_data(attr[nl80211.NL80211_ATTR_SSID]))
        if nl80211.NL80211_ATTR_IFTYPE in attr:
            iftype = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFTYPE])
            print("\ttype %s" % nl80211.nl80211_iftype2str[iftype])
        if nl80211.NL80211_ATTR_WIPHY_FREQ in attr:
            freq = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY_FREQ])

            sys.stdout.write("\tfreq %d MHz" % freq)

            if nl80211.NL80211_ATTR_CHANNEL_WIDTH in attr:
                chanw = nl.nla_get_u32(
                    attr[nl80211.NL80211_ATTR_CHANNEL_WIDTH])
                sys.stdout.write(", width: %s" %
                                 nl80211.nl80211_chan_width2str[chanw])
                if nl80211.NL80211_ATTR_CENTER_FREQ1 in attr:
                    sys.stdout.write(", center1: %d MHz" % nl.nla_get_u32(
                        attr[nl80211.NL80211_ATTR_CENTER_FREQ1]))
                if nl80211.NL80211_ATTR_CENTER_FREQ2 in attr:
                    sys.stdout.write(", center2: %d MHz" % nl.nla_get_u32(
                        attr[nl80211.NL80211_ATTR_CENTER_FREQ2]))
            elif nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE in attr:
                channel_type = nl.nla_get_u32(
                    attr[nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE])
                sys.stdout.write(
                    " %s" % nl80211.nl80211_channel_type2str(channel_type))

            sys.stdout.write("\n")
        return nl.NL_SKIP
    except Exception as e:
        (t, v, tb) = sys.exc_info()
        print v.message
        traceback.print_tb(tb)
示例#2
0
文件: base.py 项目: oprsystem/py80211
    def store_attrs(self, attrs):
        for aid in attrs.keys():
            try:
                pol = self._policy[aid]
                if pol.type == NLA_S8:
                    pol.type = nl.NLA_U8
                    pol.signed = True
                elif pol.type == NLA_S16:
                    pol.type = nl.NLA_U16
                    pol.signed = True
                elif pol.type == NLA_S32:
                    pol.type = nl.NLA_U32
                    pol.signed = True
                elif pol.type == NLA_S64:
                    pol.type = nl.NLA_U64
                    pol.signed = True

                if pol.type == NLA_NUL_STRING:
                    self._attrs[aid] = nl.nla_get_string(attrs[aid])
                elif pol.type == nl.NLA_U64:
                    self._attrs[aid] = nl.nla_get_u64(attrs[aid])
                elif pol.type == nl.NLA_U32:
                    self._attrs[aid] = nl.nla_get_u32(attrs[aid])
                elif pol.type == nl.NLA_U16:
                    self._attrs[aid] = nl.nla_get_u16(attrs[aid])
                elif pol.type == nl.NLA_U8:
                    self._attrs[aid] = nl.nla_get_u8(attrs[aid])
                elif pol.type == nl.NLA_FLAG:
                    self._attrs[aid] = True
                elif pol.type == nl.NLA_NESTED:
                    if hasattr(pol, 'single') and pol.single:
                        obj = self.create_nested(attrs[aid], aid)
                    elif hasattr(pol, 'map') and pol.map:
                        if not hasattr(pol, 'list_type'):
                            raise Exception(
                                'need to specify "list_type" for map')
                        obj = self.create_map(attrs[aid], pol)
                    elif hasattr(pol, 'list_type'):
                        obj = self.create_list(attrs[aid], pol)
                    else:
                        obj = self.create_nested_list(attrs[aid], aid)
                    self.merge_nested_attrs(aid, obj)
                elif pol.type in [NLA_BINARY, nl.NLA_UNSPEC]:
                    self._attrs[aid] = nl.nla_data(attrs[aid])
                if hasattr(pol, 'signed') and pol.signed:
                    self._attrs[aid] = self.convert_sign(self._attrs[aid], pol)
            except Exception as e:
                print e.message
                self._attrs[aid] = nl.nla_data(attrs[aid])
        self.post_store_attrs(attrs)
示例#3
0
文件: base.py 项目: arend/py80211
	def store_attrs(self, attrs):
		for aid in attrs.keys():
			try:
				pol = self._policy[aid]
				if pol.type == NLA_S8:
					pol.type = NLA_U8
					pol.signed = True
				elif pol.type == NLA_S16:
					pol.type = NLA_U16
					pol.signed = True
				elif pol.type == NLA_S32:
					pol.type = NLA_U32
					pol.signed = True
				elif pol.type == NLA_S64:
					pol.type = NLA_U64
					pol.signed = True

				if pol.type == NLA_NUL_STRING:
					self._attrs[aid] = nla_get_string(attrs[aid])
				elif pol.type == NLA_U64:
					self._attrs[aid] = nla_get_u64(attrs[aid])
				elif pol.type == NLA_U32:
					self._attrs[aid] = nla_get_u32(attrs[aid])
				elif pol.type == NLA_U16:
					self._attrs[aid] = nla_get_u16(attrs[aid])
				elif pol.type == NLA_U8:
					self._attrs[aid] = nla_get_u8(attrs[aid])
				elif pol.type == NLA_FLAG:
					self._attrs[aid] = True
				elif pol.type == NLA_NESTED:
					if hasattr(pol, 'single') and pol.single:
						obj = self.create_nested(attrs[aid], aid)
					elif hasattr(pol, 'map') and pol.map:
						if not hasattr(pol, 'list_type'):
							raise Exception('need to specify "list_type" for map')
						obj = self.create_map(attrs[aid], pol)
					elif hasattr(pol, 'list_type'):
						obj = self.create_list(attrs[aid], pol)
					else:
						obj = self.create_nested_list(attrs[aid], aid)
					self.merge_nested_attrs(aid, obj)
				elif pol.type in [ NLA_BINARY, NLA_UNSPEC ]:
					self._attrs[aid] = nla_data(attrs[aid])
				if hasattr(pol, 'signed') and pol.signed:
					self._attrs[aid] = self.convert_sign(self._attrs[aid], pol)
			except Exception as e:
				print e.message
				self._attrs[aid] = nla_data(attrs[aid])
		self.post_store_attrs(attrs)
示例#4
0
def msg_handler(m, a):
    try:
        e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
                                        nl80211.NL80211_ATTR_MAX, None)
        if nl80211.NL80211_ATTR_WIPHY_NAME in attr:
            print('wiphy %s' %
                  nl.nla_get_string(attr[nl80211.NL80211_ATTR_WIPHY_NAME]))
        if nl80211.NL80211_ATTR_WIPHY_BANDS in attr:
            fpol = nl.nla_policy_array(nl80211.NL80211_FREQUENCY_ATTR_MAX + 1)
            fpol[nl80211.NL80211_FREQUENCY_ATTR_FREQ].type = nl.NLA_U32
            fpol[nl80211.NL80211_FREQUENCY_ATTR_DISABLED].type = nl.NLA_FLAG
            fpol[
                nl80211.NL80211_FREQUENCY_ATTR_PASSIVE_SCAN].type = nl.NLA_FLAG
            fpol[nl80211.NL80211_FREQUENCY_ATTR_NO_IBSS].type = nl.NLA_FLAG
            fpol[nl80211.NL80211_FREQUENCY_ATTR_RADAR].type = nl.NLA_FLAG
            fpol[nl80211.NL80211_FREQUENCY_ATTR_MAX_TX_POWER].type = nl.NLA_U32

            nattrs = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_WIPHY_BANDS])
            for nattr in nattrs:
                handle_band(nattr, fpol)
        if nl80211.NL80211_ATTR_CIPHER_SUITES in attr:
            ciphers = nl.nla_data(attr[nl80211.NL80211_ATTR_CIPHER_SUITES])
            num = len(ciphers) / 4
            if num > 0:
                print("\tSupported Ciphers:")
                for i in range(0, num, 4):
                    print("\t\t* %s" % cipher_name(ciphers[i:i + 4]))
        if nl80211.NL80211_ATTR_SUPPORTED_IFTYPES in attr:
            print("\tSupported interface modes:")
            ifattr = nl.nla_get_nested(
                attr[nl80211.NL80211_ATTR_SUPPORTED_IFTYPES])
            for nl_mode in ifattr:
                print("\t\t* %s" %
                      nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
        if nl80211.NL80211_ATTR_SOFTWARE_IFTYPES in attr:
            print("\tsoftware interface modes (can always be added):")
            ifattr = nl.nla_get_nested(
                attr[nl80211.NL80211_ATTR_SOFTWARE_IFTYPES])
            for nl_mode in ifattr:
                print("\t\t* %s" %
                      nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
        return nl.NL_SKIP
    except Exception as e:
        (t, v, tb) = sys.exc_info()
        print v.message
        traceback.print_tb(tb)
示例#5
0
文件: base.py 项目: oprsystem/py80211
 def create_list(self, attr_list, pol):
     nest_list = []
     item_type = pol.list_type
     for item in nl.nla_get_nested(attr_list):
         if item_type == NLA_NUL_STRING:
             nest_obj = nl.nla_get_string(item)
         elif item_type == nl.NLA_U64:
             nest_obj = nl.nla_get_u64(item)
         elif item_type == nl.NLA_U32:
             nest_obj = nl.nla_get_u32(item)
         elif item_type == nl.NLA_U16:
             nest_obj = nl.nla_get_u16(item)
         elif item_type == nl.NLA_U8:
             nest_obj = nl.nla_get_u8(item)
         else:
             raise Exception("type (%d) not supported for list" % item_type)
         nest_list.append(nest_obj)
     return nest_list
示例#6
0
文件: base.py 项目: arend/py80211
	def create_list(self, attr_list, pol):
		nest_list = []
		item_type = pol.list_type
		for item in nla_get_nested(attr_list):
			if item_type == NLA_NUL_STRING:
				nest_obj = nla_get_string(item)
			elif item_type == NLA_U64:
				nest_obj = nla_get_u64(item)
			elif item_type == NLA_U32:
				nest_obj = nla_get_u32(item)
			elif item_type == NLA_U16:
				nest_obj = nla_get_u16(item)
			elif item_type == NLA_U8:
				nest_obj = nla_get_u8(item)
			else:
				raise Exception("type (%d) not supported for list" % item_type)
			nest_list.append(nest_obj)
		return nest_list
示例#7
0
def msg_handler(m, a):
	try:
		e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
						nl80211.NL80211_ATTR_MAX, None)
		if nl80211.NL80211_ATTR_WIPHY in attr:
			thiswiphy = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY])
			print("phy#%d" % thiswiphy)
		if nl80211.NL80211_ATTR_IFNAME in attr:
			print("\tinterface %s" % nl.nla_get_string(attr[nl80211.NL80211_ATTR_IFNAME]));
		if nl80211.NL80211_ATTR_IFINDEX in attr:
			print("\tifindex %d" % nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFINDEX]))
		if nl80211.NL80211_ATTR_WDEV in attr:
			print("\twdev 0x%lx" % nl.nla_get_u64(attr[nl80211.NL80211_ATTR_WDEV]))
		if nl80211.NL80211_ATTR_MAC in attr:
			print("\tmac %02x:%02x:%02x:%02x:%02x:%02x" % tuple(nl.nla_data(attr[nl80211.NL80211_ATTR_MAC])))
		if nl80211.NL80211_ATTR_SSID in attr:
			print("\tssid ", nl.nla_data(attr[nl80211.NL80211_ATTR_SSID]))
		if nl80211.NL80211_ATTR_IFTYPE in attr:
			iftype = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFTYPE])
			print("\ttype %s" % nl80211.nl80211_iftype2str[iftype])
		if nl80211.NL80211_ATTR_WIPHY_FREQ in attr:
			freq = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY_FREQ])

			sys.stdout.write("\tfreq %d MHz" % freq);

			if nl80211.NL80211_ATTR_CHANNEL_WIDTH in attr:
				chanw = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_CHANNEL_WIDTH])
				sys.stdout.write(", width: %s" % nl80211.nl80211_chan_width2str[chanw])
				if nl80211.NL80211_ATTR_CENTER_FREQ1 in attr:
					sys.stdout.write(", center1: %d MHz" %
						nl.nla_get_u32(attr[nl80211.NL80211_ATTR_CENTER_FREQ1]))
				if nl80211.NL80211_ATTR_CENTER_FREQ2 in attr:
					sys.stdout.write(", center2: %d MHz" %
						nl.nla_get_u32(attr[nl80211.NL80211_ATTR_CENTER_FREQ2]))
			elif nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE in attr:
				channel_type = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE])
				sys.stdout.write(" %s" % nl80211.nl80211_channel_type2str(channel_type));

			sys.stdout.write("\n");
		return nl.NL_SKIP;
	except Exception as e:
		(t,v,tb) = sys.exc_info()
		print v.message
		traceback.print_tb(tb)
示例#8
0
def msg_handler(m, a):
	try:
		e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
						nl80211.NL80211_ATTR_MAX, None)
		if nl80211.NL80211_ATTR_WIPHY_NAME in attr:
			print('wiphy %s' % nl.nla_get_string(attr[nl80211.NL80211_ATTR_WIPHY_NAME]))
		if nl80211.NL80211_ATTR_WIPHY_BANDS in attr:
			fpol = nl.nla_policy_array(nl80211.NL80211_FREQUENCY_ATTR_MAX + 1)
			fpol[nl80211.NL80211_FREQUENCY_ATTR_FREQ].type = nl.NLA_U32
			fpol[nl80211.NL80211_FREQUENCY_ATTR_DISABLED].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_PASSIVE_SCAN].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_NO_IBSS].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_RADAR].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_MAX_TX_POWER].type = nl.NLA_U32

			nattrs = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_WIPHY_BANDS])
			for nattr in nattrs:
				handle_band(nattr, fpol)
		if nl80211.NL80211_ATTR_CIPHER_SUITES in attr:
			ciphers = nl.nla_data(attr[nl80211.NL80211_ATTR_CIPHER_SUITES])
			num = len(ciphers) / 4
			if num > 0:
				print("\tSupported Ciphers:");
				for i in range(0, num, 4):
					print("\t\t* %s" % cipher_name(ciphers[i:i+4]))
		if nl80211.NL80211_ATTR_SUPPORTED_IFTYPES in attr:
			print("\tSupported interface modes:")
			ifattr = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_SUPPORTED_IFTYPES])
			for nl_mode in ifattr:
				print("\t\t* %s" % nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
		if nl80211.NL80211_ATTR_SOFTWARE_IFTYPES in attr:
			print("\tsoftware interface modes (can always be added):")
			ifattr = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_SOFTWARE_IFTYPES])
			for nl_mode in ifattr:
				print("\t\t* %s" % nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
		return nl.NL_SKIP
	except Exception as e:
		(t,v,tb) = sys.exc_info()
		print v.message
		traceback.print_tb(tb)
示例#9
0
	def store_attrs(self, attrs):
		for attr in attrs.keys():
			try:
				pol = self._policy[attr]
				if pol.type == NLA_NUL_STRING:
					self._attrs[attr] = nl.nla_get_string(attrs[attr])
				elif pol.type == nl.NLA_U64:
					self._attrs[attr] = nl.nla_get_u64(attrs[attr])
				elif pol.type == nl.NLA_U32:
					self._attrs[attr] = nl.nla_get_u32(attrs[attr])
				elif pol.type == nl.NLA_U16:
					self._attrs[attr] = nl.nla_get_u16(attrs[attr])
				elif pol.type == nl.NLA_U8:
					self._attrs[attr] = nl.nla_get_u8(attrs[attr])
				elif pol.type == nl.NLA_FLAG:
					self._attrs[attr] = True
				elif pol.type == nl.NLA_NESTED:
					self.store_nested(attrs[attr], attr)
				elif pol.type in [ NLA_BINARY, nl.NLA_UNSPEC ]:
					self._attrs[attr] = nl.nla_data(attrs[attr])
			except Exception as e:
				print e.message
				self._attrs[attr] = nl.nla_data(attrs[attr])
示例#10
0
 def store_attrs(self, attrs):
     for attr in attrs.keys():
         try:
             pol = self._policy[attr]
             if pol.type == NLA_NUL_STRING:
                 self._attrs[attr] = nl.nla_get_string(attrs[attr])
             elif pol.type == nl.NLA_U64:
                 self._attrs[attr] = nl.nla_get_u64(attrs[attr])
             elif pol.type == nl.NLA_U32:
                 self._attrs[attr] = nl.nla_get_u32(attrs[attr])
             elif pol.type == nl.NLA_U16:
                 self._attrs[attr] = nl.nla_get_u16(attrs[attr])
             elif pol.type == nl.NLA_U8:
                 self._attrs[attr] = nl.nla_get_u8(attrs[attr])
             elif pol.type == nl.NLA_FLAG:
                 self._attrs[attr] = True
             elif pol.type == nl.NLA_NESTED:
                 self.store_nested(attrs[attr], attr)
             elif pol.type in [NLA_BINARY, nl.NLA_UNSPEC]:
                 self._attrs[attr] = nl.nla_data(attrs[attr])
         except Exception as e:
             print e.message
             self._attrs[attr] = nl.nla_data(attrs[attr])