Disclosure of Invention
The embodiment of the specification provides a method and a device for acquiring a MAC address, which are used for solving the problem that in the prior art, when a WiFi probe acquires a randomly generated MAC address, subsequent service cannot be continued based on the acquired randomly generated MAC address.
The embodiment of the specification adopts the following technical scheme:
a method of collecting MAC addresses, comprising:
receiving each management frame transmitted in a broadcasting mode, and respectively determining the MAC address carried in each management frame;
for each determined MAC address, determining the address type of the MAC address and the equipment type corresponding to the MAC address, wherein the address type at least comprises: legal MAC address and random MAC address, the said apparatus type includes at least: a normal device and a wireless Access Point (AP) device;
sequentially storing each MAC address of which the determined equipment type is AP equipment;
when the address type of any MAC address is determined to be a random MAC address, a beacon frame is sequentially generated and broadcast according to the stored device types as each MAC address of the AP device, so that a terminal broadcasting a management frame carrying the random MAC address returns a management frame carrying a legal MAC address when receiving a reliable beacon frame.
An apparatus for collecting MAC addresses, comprising:
the receiving and determining module is used for receiving each management frame transmitted in a broadcasting mode and respectively determining the MAC address carried in each management frame;
the classifying module is used for determining the address type of the MAC address and the equipment type corresponding to the MAC address according to each determined MAC address, wherein the address type at least comprises: legal MAC address and random MAC address, the said apparatus type includes at least: a normal device and a wireless Access Point (AP) device;
the storage module sequentially stores each MAC address of which the determined equipment type is AP equipment;
and the broadcasting module sequentially generates and broadcasts beacon frames according to the stored equipment types as the MAC addresses of the AP equipment when the address type of any MAC address is determined to be the random MAC address, so that a terminal broadcasting the management frame carrying the random MAC address returns the management frame carrying the legal MAC address when receiving the reliable beacon frame.
The above-mentioned at least one technical scheme that this description embodiment adopted can reach following beneficial effect:
according to the method and the device provided by the specification, the WiFi probe can classify the MAC addresses in the received management frames, determine whether the management frames sent by different devices and the MAC addresses are legal, and when the fact that the management frames carrying random MAC addresses exist in the broadcasted management frames is determined, sequentially generate a plurality of beacon frames to broadcast according to the acquired MAC addresses broadcasted by the wireless access point (WirelessAccessPoint, AP) devices, so that a terminal sending the management frames carrying the random MAC addresses returns the management frames carrying legal MAC addresses when receiving reliable beacon frames. The Wifi probe can store the acquired MAC addresses of all surrounding AP devices in sequence, and when receiving the management frame carrying the random MAC address, the Wifi probe can generate a beacon frame through the stored MAC address of each AP device and broadcast the beacon frame, so that the terminal broadcasting the management frame carrying the random MAC address returns the management frame carrying the legal MAC address to the Wifi probe when receiving the reliable beacon frame broadcasted by the Wifi probe. The method and the device solve the defect that the WiFi probe in the prior art has the function of acquiring legal MAC addresses.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the present specification more apparent, the technical solutions of the present application will be clearly and completely described below with reference to specific embodiments of the present specification and corresponding drawings. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the disclosure, are intended to be within the scope of the present application based on the embodiments described herein.
The following describes in detail the technical solutions provided by the embodiments of the present application with reference to the accompanying drawings.
Fig. 1 is a schematic diagram of a process for acquiring a MAC address according to an embodiment of the present application, which may specifically include the following steps:
s100: and receiving each management frame transmitted by a broadcasting mode, and respectively determining the MAC address carried in each management frame.
In the prior art, the function of acquiring the MAC address by the WiFi probe in early stage is integrated on the AP device, that is, the AP device provides network service for the accessed terminal, and also receives signals broadcast by surrounding non-accessed terminals, and determines the MAC address from the received signals. However, when the AP device acquires the MAC address, the AP device may interfere with the quality of network service provided by the AP device, and the efficiency of acquiring the MAC address by the AP device is also low, so as to enable the AP device to acquire the MAC address by using an independent device instead of integrating the function of acquiring the MAC address in the AP device along with the progress of the technology. That is, the WiFi probe of the prior art is an independent device, and is not used for providing network services for the mobile terminal any more, but is only used for acquiring the MAC address of the mobile terminal for subsequent execution of the service.
Similarly, in one or more embodiments of the present application, the process of collecting the MAC address may also be performed by a WiFi probe, which is a stand-alone device that does not include functionality to provide network services for the mobile terminal. The WiFi probe may then be acquired via an antenna with surrounding management frames broadcast by the device with the connected WLAN capability. Wherein, the management frame accords with the IEEE 802.11 standard, and the management frame can also carry a MAC address.
Specifically, how the WiFi probe acquires the broadcasted management frame is a mature method in the prior art, and the content of the process is not described in detail in this application.
It should be noted that, in the embodiment of the present application, the device having the function of connecting to the WLAN may specifically include: mobile terminals (e.g., cell phones, tablet computers, etc.) and AP devices. Therefore, the WiFi probe can acquire the management frame broadcast by the mobile terminal and can also receive the management frame broadcast by the AP equipment. In addition, the management frame in the present application may include at least: both Beacon frames (Beacon frames) and probe request frames, since a mobile terminal is typically the party that needs to access a WLAN, the management frames broadcast by the mobile terminal are typically probe request frames, while the AP device is the party that provides WLAN access, and the management frames broadcast by the AP device are typically Beacon frames (Beacon frames).
In addition, since the content of the management frame needs to conform to the IEEE 802.11 standard when the device broadcasts the management frame, the management frame carries the MAC address. The WiFi terminal may then also determine the MAC address carried in each management frame received. Of course, the MAC address may be a legitimate MAC address of the device (i.e., a real address of the device provided when connecting to the network), or the MAC address may be a MAC address randomly generated by the device.
S102: and determining the address type of the MAC address and the equipment type corresponding to the MAC address aiming at each determined MAC address.
S104: and sequentially storing each MAC address of which the determined equipment type is the AP equipment.
In one or more embodiments of the present application, since the device sending the MAC is that device, whether the MAC address is a real address or not is specified in the IEEE 802.11 standard, after determining the MAC address carried in the management frame, the WiFi probe may further determine, for each MAC address, an address type of the MAC address and a device type corresponding to the MAC address. Wherein the address type includes: legal MAC address and random MAC address, the device type at least includes: an AP device.
Specifically, the WiFi probe may determine the type of the MAC address first, and for each determined MAC address, determine whether the value of the b1 bit (bit) in the first byte of the MAC address is 0, if so, determine that the address type of the MAC address is a legal MAC address and store the legal MAC address, and if not, determine that the address type of the MAC address is a random address and not store the random address. The WiFi probe may be provided to a background server for the determined legal MAC address, so that the background server may perform services (e.g., traffic statistics and analysis, precision marketing, public safety, etc.) as needed.
Of course, in this embodiment of the present application, the WiFi probe may store the determined legal MAC address locally, and send the determined legal MAC address to the background server when the number of stored legal MAC addresses reaches a preset value, or send the stored legal MAC address to the background server according to a preset time interval.
In addition, as described in step S100, since the management frame received by the WiFi probe may be a probe request frame broadcast by the mobile terminal or a beacon frame broadcast by the AP device, and the MAC address of the AP device is not generally used for executing the service by the subsequent background server, in this embodiment of the present application, the WiFi probe may further determine, from the determined MAC addresses, that the device type is the MAC address of the AP device and store the determined MAC address, but may not send the determined MAC address to the background server to reduce the communication pressure.
Further, since the MAC address of the AP device is used for the mobile terminal to establish a communication connection with the AP device, the MAC address carried in the broadcast beacon frame of the AP device is a legal MAC address. In this embodiment of the present application, after determining each legal MAC address, the WiFi probe may determine whether the device type corresponding to the legal MAC address is an AP device, if so, store the MAC addresses in the linked list in sequence, and if not, directly store the MAC addresses for sending to the background server.
Furthermore, when the WiFi probe stores the determined MAC address of the AP device in the linked list, the WiFi probe may store the MAC address according to the time sequence of receiving the management frame carrying the MAC address. And the number of the MAC addresses stored in the linked list can be set according to the requirement, when the linked list is full and the newly determined MAC address of the AP equipment is required to be stored, the WiFi probe can delete the MAC address stored in the linked list at the earliest time and then determine the MAC address of the AP equipment. For example, assuming that the linked list of WiFi probes has a capacity of 5, five MAC addresses a1 to a5 are stored in chronological order, after determining a new MAC address a6 to be stored in the linked list, the MAC address a1 may be deleted, and five MAC addresses a2 to a6 may be stored.
In addition, since the location of the WiFi probe is generally fixed, and the surrounding AP devices are generally fixed, the WiFi probe may perform the outbound processing after determining each MAC address, and when the MAC address coincides with any one of the MAC addresses already stored, the MAC address is not processed for each determined MAC address.
S106: when the address type of any MAC address is determined to be a random MAC address, a beacon frame is sequentially generated and broadcast according to the stored device types as each MAC address of the AP device.
In one or more embodiments of the present application, when determining that the address type of any MAC address is a random MAC address, it may be determined that the MAC address cannot be used for a subsequent server to perform a service, so the WiFi probe may also sequentially generate and broadcast a beacon frame according to the stored device type that is each MAC address of the AP device. And when the terminal broadcasting the management frame carrying the random MAC address receives the beacon true frame broadcasted by the WiFi probe and determines that the beacon frame is reliable, returning the management frame carrying the legal MAC address to the WiFi probe. The WiFi probe may determine and store the legitimate MAC address through step S100 and step S102.
Specifically, as illustrated in step S100, in one or more embodiments of the present application, the WiFi probe does not have a function of providing a network service, and is a device that passively accepts broadcasted management frames. Therefore, in order to realize the function of broadcasting beacon frames, in step S106, a main program executable by the central processing unit (Central Processing Unit, CPU) of the WiFi probe, according to AT instructions stored in a nonvolatile memory (e.g., ROM) is called by service logic, parameters adopted when the antenna of the WiFi probe broadcasts signals are configured, and beacon frames are sequentially generated for each MAC address of the AP device according to the stored device type, and each beacon frame sequentially generated is sequentially broadcast in the order of generation through the antenna.
That is, the WiFi probe configures itself as a device that can broadcast a signal according to a pre-configured AT command and service logic of a main program, and broadcasts a generated beacon frame. The AT command may be preconfigured in the ROM of the WiFi probe as needed. And the WiFi probe is configured through the AT instruction, so that the existing WiFi probe without the network service function can realize broadcasting of a beacon frame on the basis of not changing a hardware structure, and the upgrading cost of the WiFi probe is reduced. Meanwhile, as the WiFi probe does not have a network service function, the function of the WiFi probe can be intensively used for acquiring the MAC address, and the efficiency is higher than that of the AP equipment integrating the function of acquiring the MAC address in the prior art.
In addition, since the WiFi probe performs chain storage of the determined MAC address of the AP device in step S104, the WiFi probe may sequentially generate a beacon frame including the MAC address according to the stored MAC address for each AP device and broadcast the beacon frame. Therefore, the WiFi probe can complete the broadcasting of the beacon frame without interfering with the acquisition of the management frame.
Further, since the terminal generally identifies the network identifier of the beacon frame and determines whether the beacon frame is a trusted beacon frame when receiving the beacon frame, in step S104 of the embodiment of the present application, the WiFi probe may further determine, for each MAC address of the AP device, a network identifier in a management frame carrying each MAC address, and establish and store a correspondence between the MAC address and the determined network identifier. In step S106, when the WiFi probe generates a beacon frame, for each called MAC address in turn, according to the stored correspondence between each MAC address and each network identifier, the network identifier corresponding to the MAC address is determined, and then, according to the MAC address and the network identifier corresponding to the MAC address, a beacon frame carrying the MAC address and the network identifier is generated. The network identity may be a service set identity (Service Set Identifier, SSID), among others.
When the terminal determines whether the beacon frame is trustworthy, it may determine whether the MAC address corresponding to the beacon frame is connected according to the history of connecting to the WLAN, if so, it determines that the beacon frame is trustworthy, and if not, it determines that the beacon frame is not trustworthy. Or, the terminal may also determine whether the beacon frame is trustable according to a pre-acquired MAC address white list and/or a pre-acquired black list, which is not limited by the specific determination method of the terminal. However, as long as the terminal determines that the beacon frame broadcast by the WiFi probe is trusted, a management frame carrying a legal MAC address is provided, the WiFi probe may perform step S100 to determine the legal MAC address through the management frame, and continue to perform subsequent steps.
Through the method for acquiring the MAC address shown in fig. 1, the WiFi probe may sequentially store the acquired MAC addresses of surrounding AP devices, and when receiving the management frame carrying the random MAC address, generate a beacon frame through the stored MAC addresses of the AP devices and broadcast the beacon frame, so that the terminal broadcasting the management frame carrying the random MAC address returns the management frame carrying the legal MAC address to the WiFi probe when receiving the reliable beacon frame broadcast by the WiFi probe. The method and the device solve the defect that the WiFi probe in the prior art has the function of acquiring legal MAC addresses.
In addition, in the embodiment of the present application, since the validity of the MAC address of the AP device obtained by the WiFi probe is generally reduced with time, the WiFi probe may further determine, for each stored MAC address of the AP device, whether the MAC address is overtime, if so, delete the MAC address, and if not, do not perform processing.
Further, when the WiFi probe broadcasts the beacon frames in sequence in step S106, the WiFi probe may also broadcast the generated beacon frames in sequence according to a preset time interval because the broadcast beacon frames interfere with the reception management frames. The time interval may be set (e.g., 5 seconds) according to needs, which is not limited in this application.
Further, in the embodiment of the present application, in order to reduce the resources consumed by the WiFi probe, the WiFi probe may further not execute the step S106 when the number of management frames acquired in the step S100 is less than the preset number. That is, when the number of surrounding terminals is small, even when a management frame carrying a random MAC address is received, a beacon frame is not generated to broadcast, but the random MAC address is ignored so as to concentrate the resources of the WiFi probe on determining the MAC address. The preset number may be set as required, for example, the preset number may be higher (e.g., 10) WiFi probes set in places with larger people flows, the preset number may be lower (e.g., 1) WiFi probes set in places with smaller people flows, and the like, which is not limited in this application.
Based on the method for acquiring the MAC address provided in fig. 1, the present application further correspondingly provides an apparatus for acquiring the MAC address, as shown in fig. 2.
Fig. 2 is a schematic structural diagram of an apparatus for acquiring a MAC address according to an embodiment of the present application, including:
the receiving and determining module 200 receives each management frame propagated in a broadcast manner and determines the MAC address carried in each management frame respectively;
the classifying module 202 determines, for each determined MAC address, an address type of the MAC address and a device type corresponding to the MAC address, where the address types at least include: legal MAC address and random MAC address, the said apparatus type includes at least: a normal device and a wireless Access Point (AP) device;
the storage module 204 sequentially stores each MAC address of the determined equipment type as the AP equipment;
and a broadcasting module 206, when determining that the address type of any one of the MAC addresses is a random MAC address, generating beacon frames in sequence according to the stored device types as each MAC address of the AP device and broadcasting the beacon frames, so that the terminal broadcasting the management frame carrying the random MAC address returns the management frame carrying the legal MAC address when receiving the trusted beacon frame.
The storage module 204 sequentially stores each MAC address of the AP device with the device type in the linked list according to the determined time sequence of each MAC address of the AP device with the device type.
The broadcasting module 206 sequentially calls each MAC address of the AP device with the device type according to the stored linked list, generates a beacon frame, and broadcasts the beacon frame.
The classifying module 202 determines, for each MAC address of the AP device, a network identifier in a management frame carrying each MAC address; the storage module 204 establishes and stores the corresponding relationship between the MAC address and the determined network identifier; the broadcasting module 206 determines, for each called MAC address, a network identifier corresponding to the MAC address according to the stored correspondence between each MAC address and each network identifier, and generates a beacon frame according to the MAC address and the network identifier corresponding to the MAC address.
The broadcasting module 206 invokes and executes AT least one AT instruction stored in advance when determining that the address type of any MAC address is a random MAC address, configures parameters of an antenna broadcast signal, sequentially generates beacon frames for each MAC address of an AP device according to the stored device type, and sequentially broadcasts each beacon frame according to the generation sequence through the antenna according to the configured parameters of the broadcast signal.
The foregoing is merely exemplary of the present application and is not intended to limit the present application. Various modifications and changes may be made to the present application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. which are within the spirit and principles of the present application are intended to be included within the scope of the claims of the present application.