CN113490197A - Information acquisition method and device and storage medium - Google Patents

Information acquisition method and device and storage medium Download PDF

Info

Publication number
CN113490197A
CN113490197A CN202110642479.9A CN202110642479A CN113490197A CN 113490197 A CN113490197 A CN 113490197A CN 202110642479 A CN202110642479 A CN 202110642479A CN 113490197 A CN113490197 A CN 113490197A
Authority
CN
China
Prior art keywords
target
peer
address
information
network
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110642479.9A
Other languages
Chinese (zh)
Inventor
柳建双
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen TCL New Technology Co Ltd
Original Assignee
Shenzhen TCL New Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen TCL New Technology Co Ltd filed Critical Shenzhen TCL New Technology Co Ltd
Priority to CN202110642479.9A priority Critical patent/CN113490197A/en
Publication of CN113490197A publication Critical patent/CN113490197A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W8/00Network data management
    • H04W8/005Discovery of network devices, e.g. terminals
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/10Mapping addresses of different types
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W76/00Connection management
    • H04W76/10Connection setup
    • H04W76/14Direct-mode setup

Abstract

The embodiment of the application discloses an information acquisition method, an information acquisition device and a storage medium, wherein peer-to-peer network connection is established with target equipment by searching the target equipment; receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information; determining a target MAC address of the target device based on the peer-to-peer network group information; acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address; and searching the internet protocol address corresponding to the target media access control address based on the adjacent equipment address list. Therefore, the efficiency of acquiring the internet protocol address of the target device is improved.

Description

Information acquisition method and device and storage medium
Technical Field
The present application relates to the field of communications technologies, and in particular, to an information acquisition method, an information acquisition apparatus, a storage medium, and a computer device.
Background
The WiFi Direct (WiFi-Direct) standard refers to a standard that allows devices in a wireless network to connect to each other without passing through a wireless router. Similar to bluetooth technology, this standard allows wireless devices to be interconnected in a point-to-point (P2P) manner, and has a significantly improved transmission speed and transmission distance compared to bluetooth. In the framework of WiFi direct connection, after the device is successfully connected, the device may serve as a Group Owner (GO) role or a group user (GC) role, and transmit data by acquiring an IP Address (Internet Protocol Address) of the peer device. However, when the local device is in the GO role and its peer device is in the GC role, the local device cannot directly acquire the IP address of the peer device.
In the prior art, the IP Address of the peer device is mostly obtained by additionally creating a Socket (Socket) or obtaining an Address Resolution Protocol (ARP) node Address cache table, but these methods are either complicated, or need to wait for an active connection request of the peer device to obtain the IP Address, and cannot guarantee that the IP Address of the peer device can be obtained in time, so that the efficiency of obtaining the IP Address of the peer device is low.
Disclosure of Invention
The embodiment of the application provides an information acquisition method, an information acquisition device and a storage medium. The efficiency of obtaining the internet protocol address of the peer device may be improved.
An information acquisition method, comprising:
searching target equipment and establishing peer-to-peer network connection with the target equipment;
receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information;
determining a target MAC address of the target device based on the peer-to-peer network group information;
acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address;
and searching an internet protocol address corresponding to the target media access control address based on the adjacent equipment address list.
Correspondingly, an embodiment of the present application provides an information obtaining apparatus, including:
a search unit configured to search for a target device and establish a peer-to-peer network connection with the target device;
a receiving unit, configured to receive target broadcast information, and obtain peer-to-peer network group information according to the target broadcast information;
a determining unit, configured to determine a mac address of the target device according to the peer-to-peer network group information;
an acquisition unit configured to acquire a neighboring device address list;
and the searching unit is used for searching the Internet protocol address corresponding to the target media access control address based on the adjacent equipment address list.
In one embodiment, the search unit includes:
a first searching subunit, configured to search each mac address entry in the neighboring device address list according to the target mac address;
the first obtaining subunit is configured to, when a target mac address item corresponding to the target mac address is searched, obtain an ip address in a row of the target mac address item, where the ip address is an ip address of the target device.
In an embodiment, the information acquiring apparatus further includes:
and the arranging unit is used for classifying and arranging each row of address information in the adjacent equipment address list according to the network hardware manufacturer number of the MAC address.
In one embodiment, the search unit includes:
a determining subunit, configured to determine a target network hardware manufacturer number in the target mac address;
a second obtaining subunit, configured to obtain a mac address item set, where a network hardware manufacturer number in the neighboring device address list is the same as the target network hardware manufacturer number;
a second searching subunit, configured to search the mac address entry set for a target mac address entry corresponding to the target mac address;
a third obtaining subunit, configured to obtain an internet protocol address in a row of the target mac address entry.
In one embodiment, the determining unit includes:
a reading subunit, configured to read the peer-to-peer network group information, and determine a group role of the target device;
a fourth obtaining unit, configured to obtain peer-to-peer network device information of the target device according to the group role;
and the inquiring subunit is used for inquiring the device address information in the peer-to-peer network device information to obtain the target media access control address of the target device.
In an embodiment, the fourth obtaining unit is configured to:
when the role type of the target equipment is a group owner role, acquiring peer-to-peer network equipment information of the target equipment by calling a first acquisition function;
and when the role type of the target equipment is the group user role, acquiring the peer-to-peer network equipment information of the target equipment by calling a second acquisition function.
In one embodiment, the receiving unit includes:
the calling subunit is used for obtaining target network information carried by the broadcast information by calling a network information request function when the target broadcast information is received;
a detecting subunit, configured to detect status information of the peer-to-peer network connection according to the target network information;
and a fifth obtaining subunit, configured to obtain, when the peer-to-peer network connection state is a connection state, peer-to-peer network group information carried by the target broadcast information.
In an embodiment, the obtaining unit includes:
and the execution subunit is used for executing the target Internet protocol command of the network configuration tool and generating a neighboring device address list.
In addition, a storage medium is further provided, where multiple instructions are stored, and the instructions are suitable for being loaded by a processor to perform any one of the steps in the information acquisition method provided in the embodiments of the present application.
In addition, the embodiment of the present application further provides a computer device, which includes a processor and a memory, where the memory stores an application program, and the processor is configured to run the application program in the memory to implement the information acquisition method provided in the embodiment of the present application.
Embodiments of the present application also provide a computer program product or a computer program, which includes computer instructions stored in a storage medium. The processor of the computer device reads the computer instructions from the storage medium, and executes the computer instructions, so that the computer device executes the steps in the information acquisition method provided by the embodiment of the application.
The embodiment of the application establishes peer-to-peer network connection with the target equipment by searching the target equipment; receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information; determining a target MAC address of the target device based on the peer-to-peer network group information; acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address; and searching the internet protocol address corresponding to the target media access control address based on the adjacent equipment address list. Therefore, the target media access control address of the target equipment is determined through the peer-to-peer network group information carried by the target broadcast information, the adjacent equipment address list is obtained, the internet protocol address corresponding to the target media access control address is searched in the adjacent equipment address list according to the target media access control address of the target equipment, and the obtaining efficiency of the internet protocol address of the target equipment is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic view of an implementation scenario of an information acquisition method provided in an embodiment of the present application;
fig. 2 is a schematic flowchart of an information obtaining method according to an embodiment of the present application;
fig. 3 is a schematic specific flowchart of an information obtaining method according to an embodiment of the present application;
fig. 4 is another schematic flow chart of an information obtaining method provided in an embodiment of the present application;
fig. 5 is a schematic structural diagram of an information acquisition apparatus provided in an embodiment of the present application;
fig. 6 is a schematic structural diagram of a computer device provided in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The embodiment of the application provides an information acquisition method, an information acquisition device and a storage medium. The information acquisition device may be integrated in a computer device, and the computer device may be a server or a terminal.
For a better understanding of the embodiments of the present application, reference is made to the following terms:
peer-to-peer network: Peer-to-Peer (Peer-to-Peer, abbreviated as P2P) is a distributed application architecture for distributing tasks and workloads among peers (peers), and is a networking or network form formed by Peer-to-Peer computing model in application layer. In a P2P network environment, multiple computer devices connected to each other are in a peer-to-peer status, each computer device has the same function, and there is no master-slave relationship, and one computer device can be used as a server (GO, i.e. group owner) to set shared resources for other computer devices in the network, and also as a workstation (GC, i.e. group user), and the whole network generally does not rely on a dedicated centralized server, nor has a dedicated workstation. Each computer in the network can both act as a requester of network services and provide resources, services and content in response to requests from other computers. Typically these resources and services include: sharing and exchange of information, computing resources (e.g., central processor computing power sharing), storage sharing (e.g., use of cache and disk space), network sharing, printer sharing, and the like.
WiFi-Direct: namely, WiFi direct connection, like WiFi P2P, can enable devices to perform point-to-point direct interconnection through a Wireless Local Area Network (WLAN) without an intermediate access point.
The peer device: in a P2P network environment, multiple computer devices connected to each other are in a peer-to-peer status, and each computer device has the same function, and has no master-slave distinction, so a device establishing peer-to-peer network connection may be called an opposite device.
IP address: the IP Address (Internet Protocol Address) refers to an Internet Protocol Address and is translated into an Internet Protocol Address. The IP address is a uniform address format provided by the IP protocol, and it allocates a logical address to each network and each host on the internet, so as to mask the difference of physical addresses.
MAC address: the MAC Address (Media Access Control Address) translates to a MAC Address, also called a local area network Address (LAN Address), a MAC Address, an Ethernet Address or a Physical Address, which is an Address used to identify the location of the network device. In an Open System Interconnection Reference Model (OSI Model for short), a third layer network layer is responsible for an IP address, and a second layer data link layer is responsible for a MAC address. The MAC address is used to uniquely identify a network card in the network, and if one or more network cards exist in a device, each network card needs to have a unique MAC address.
Socket: sockets are abstractions of endpoints that communicate bi-directionally between application processes on different hosts in a network. A socket is the end of a process's communication over a network and provides a mechanism for application layer processes to exchange data using a network protocol. In terms of the position, the socket uplink application process and the socket downlink network protocol stack are interfaces through which the application program communicates through the network protocol, and are interfaces through which the application program interacts with the network protocol root. May be used to complete the transfer of data between two endpoints, for example, may complete the transfer of data between two applications.
Referring to fig. 1, taking an information obtaining apparatus integrated in a computer device as an example, fig. 1 is a schematic view of an implementation environment scene of an information obtaining method provided in an embodiment of the present application, and includes a terminal a and a terminal B, where the terminal a and the terminal B may be various computer devices capable of performing peer-to-peer network connection, such as a smart phone, a tablet computer, a notebook computer, and a desktop computer, but are not limited thereto. The terminal a and the terminal B may be connected in a WiFi direct communication manner, and after the terminal a and the terminal B are successfully connected, the terminal a serves as a group owner, and the terminal B may be at least one terminal, so as to execute a corresponding information acquisition operation, which is not limited herein.
The terminal A and the terminal B can search target equipment and establish peer-to-peer network connection with the target equipment; receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information; determining a target MAC address of the target device based on the peer-to-peer network group information; acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address; and searching the internet protocol address corresponding to the target media access control address based on the adjacent equipment address list.
It should be noted that the schematic diagram of the implementation environment scenario of the information obtaining method shown in fig. 1 is only an example, and the implementation environment scenario of the information obtaining method described in the embodiment of the present application is for more clearly explaining the technical solution of the embodiment of the present application, and does not constitute a limitation to the technical solution provided by the embodiment of the present application. As can be known to those skilled in the art, with the evolution of information acquisition and the emergence of new service scenarios, the technical solution provided in the present application is also applicable to similar technical problems.
The following are detailed below. It should be noted that the following description of the embodiments is not intended to limit the preferred order of the embodiments.
The embodiment will be described in terms of an information acquisition apparatus, which may be specifically integrated in a computer device, where the computer device may be a terminal, and the application is not limited herein.
Referring to fig. 2, fig. 2 is a schematic flow chart of an information obtaining method according to an embodiment of the present disclosure. The information acquisition method comprises the following steps:
in step 101, a target device is searched for and a peer-to-peer network connection is established with the target device.
Under a native WiFi-Direct framework of an Android system (Android), after two devices establish peer-to-peer network connection successfully, the local device and its peer-to-peer device form a peer-to-peer network group (P2P group), and data transmission between the two devices needs to be performed through Socket connection establishment between the peer-to-peer network groups. The Socket is formed by combining an IP address and a port, and provides a mechanism for transmitting a data packet to an application layer process, so that the IP address of a peer device needs to be acquired in a peer-to-peer network group, and data transmission between two devices can be realized by establishing Socket connection.
When establishing peer-to-peer network connection, the system will automatically create a peer-to-peer network group without creating a peer-to-peer network group, and randomly allocate the role of each device in the peer-to-peer network group, when the local device is in the group user role, the peer device will be in the group owner role, the local device can directly obtain the IP address of the peer device in the group owner role, for example, the IP address of the peer device in the group owner role can be directly obtained through the wifi 2pinfo.
However, when the local device is in the group owner role, the peer device is in the group user role, and at this time, the local device can only directly acquire the MAC information of the peer device and cannot directly acquire the IP address of the peer device. In the prior art, in the case of native WiFi-Direct framework, two approaches are mostly adopted:
(1) when a WiFi-Direct connection is established between two devices, the probability that a local device is assigned to a group user role is increased by setting a group owner proposal value, that is, setting a proposal value of wifip2pconfig.
(2) When the local device is allocated to a role of a group owner, Socket connection is additionally established and monitoring is carried out, at this time, connection of the peer device needs to be waited, when the peer device actively connects, the IP address of the peer device is obtained through a Socket.
Therefore, the existing method for acquiring the IP address of the peer device is complex, needs an active connection request passively depending on the peer device, and cannot guarantee that the IP address of the peer device can be acquired in time.
Therefore, in order to solve the above problem, an embodiment of the present application provides an information obtaining method, where a target mac address of a target device is determined by receiving peer-to-peer network group information carried in target broadcast information, and a neighboring device address list is obtained, and an ip address corresponding to the target mac address is searched in the neighboring device address list according to the target mac address of the target device, so that peer-to-peer can be obtained without depending on a group role of a peer device on the basis of not changing a native WiFi-Direct framework, and meanwhile, obtaining efficiency of the ip address of the target device is improved.
The method comprises the steps that a peer-to-peer network connection service (WifiP2pService) can be created in a system service (SystemServer), the peer-to-peer network connection service is started, and then surrounding P2P devices can be searched through a startSearch () function of the WifiP2pSettings so as to establish peer-to-peer network connection with a searched target device, wherein the device for establishing peer-to-peer network connection is a peer-to-peer device in a peer-to-peer network group, the peer-to-peer network connection mode can be active connection, namely connection with the target device can be selected when the device is searched; the connection can also be passive connection, namely, a peer-to-peer network connection request sent by other P2P devices is received; the connection can also be actively invited, that is, when a peer-to-peer network group already exists, the device in the peer-to-peer network group can invite other devices to join the group, so as to form a peer-to-peer network group formed by two or more P2P devices; accordingly, a passive invitation connection may also be used, that is, a request for inviting devices in other peer-to-peer network groups to join the group is received, and the like, which is not limited herein.
In step 102, target broadcast information is received, and peer-to-peer network group information is obtained according to the target broadcast information.
The system broadcast receiver may be registered during initialization, and receive broadcast information through the broadcast receiver, and when target broadcast information is received, peer-to-peer network group information (i.e., WifiP2pGroup) is acquired according to the target broadcast information, where the target broadcast information carries status information of peer-to-peer network connection. The Broadcast is a cross-process communication mode in the Android system, and the Broadcast Receiver (Broadcast Receiver) is a standard component in the Android system and can receive information representing the change of the connection state of the peer-to-peer network.
In an embodiment, in order to ensure the accuracy of obtaining the peer-to-peer network group information, before obtaining the peer-to-peer network group information, it may be determined whether the peer device is successfully connected. Specifically, when receiving the target broadcast information, the target network information carried by the broadcast information may be acquired by calling a network information request function, and then the connection state of the device performing peer-to-peer network connection may be acquired by using the target network information. Specifically, the target NETWORK information (NetworkInfo) attached to the target broadcast information may be requested to be acquired through wifip2pmanager.extra _ NETWORK _ INFO, and it may be determined through an isConnected () function of the NetworkInfo whether the currently received target broadcast information is successfully sent out by the device in the peer-to-peer NETWORK group or sent out when the device is disconnected. When the target broadcast information is successfully sent out by the equipment in the peer-to-peer network group, the peer-to-peer equipment is indicated to be successfully connected, and then the peer-to-peer network group information is obtained.
In an embodiment, after it is confirmed that the peer device has completed the connection, the peer-to-peer network GROUP information carried by the target broadcast information may be requested to be acquired through wifip2pmanager.extra _ WIFI _ P2P _ GROUP, and the peer-to-peer network GROUP information may also be acquired through wifip2pmanager.requestgroupinfo () method.
In step 103, a target MAC address of the target device is determined according to the peer-to-peer network group information.
Reading the peer-to-peer network group information, determining the group role of the target device, further acquiring the peer-to-peer network device information of the target device according to the group role, and inquiring the device address information in the peer-to-peer network device information to obtain the target media access control address of the target device.
In an embodiment, the peer-to-peer network group information may be read by calling a role determination function to obtain call information, and a group role of the target device is determined according to the call information, specifically, the group role of the local device, that is, the isGroupOwner () function of the WifiP2pGroup, may be determined by executing the role determination function, so that the call information is received, and when the call information is "True", it indicates that the local device is a group owner role, and the peer device, that is, the group role of the target device is a group user role; when the call information is "False", it indicates that the local device is in the group user role, and the group role of the target device is in the group owner role.
In an embodiment, when the role type of the target device is a group owner role, the peer-to-peer network device information (WifiP2pDevice) of the target device may be acquired by calling a first acquisition function, i.e., the getOwner () function of WifiP2pGroup, and when the role type of the target device is a group user role, the peer-to-peer network device information (WifiP2pDevice) of the target device may be acquired by calling a second acquisition function, i.e., the getClientList () function of WifiP2 pGroup. And inquiring the device address information in the peer-to-peer network device information to obtain the target media access control address of the target device.
In step 104, a list of neighboring device addresses is obtained.
Wherein the list of neighboring device addresses may be generated by executing a target internet protocol command of the network configuration tool. The neighboring device address list includes a mapping between the mac address and the ip address of the device. The target internet protocol command is an ip command in a network configuration tool of a Linux operating system or a Linux-like operating system, and may be, for example, a neighbor option in the ip command, where the neighbor option may also be in an abbreviated form, that is, may be written as a neighbor option, an n option, and the like, and a neighbor device address list may be obtained through the target internet protocol command, and the MAC address of the device in the unified local area network may be checked through the neighbor device address list, and meanwhile, the neighbor device address list includes a mapping relationship between the media access control address of the device and the internet protocol address.
In step 105, the ip address corresponding to the target mac address is searched based on the neighboring device address list.
The mapping relation between the MAC address of the device and the IP address can be included in the neighboring device address list, and the IP address corresponding to the target MAC address can be searched in the neighboring device address list. Specifically, each mac address in the neighboring device address list may be searched according to the target mac address, and when a target mac address corresponding to the target mac address is searched, an ip address in a row where the target mac address is located is obtained. The internet protocol address is the internet protocol address of the target device.
In one embodiment, after obtaining the neighbor address list, in order to facilitate searching the content in the list and thus increase the searching speed, the neighbor address list may be sorted, specifically, since the length of the MAC address is 48 bits (i.e. 6 bytes), where the first 3 bytes represent the number of the network hardware manufacturer, and therefore, each row of address information in the neighbor address list may be sorted according to the network hardware manufacturer number of the MAC address. Furthermore, the target MAC address corresponding to the target MAC address is searched in the MAC address set by acquiring the target MAC address number in the target MAC address, and acquiring the MAC address set of the neighboring device address list, wherein the MAC address is the same as the target MAC address.
As can be seen from the above, in the embodiment of the present application, peer-to-peer network connection is established with a target device by searching the target device; receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information; determining a target MAC address of the target device based on the peer-to-peer network group information; acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address; and searching the internet protocol address corresponding to the target media access control address based on the adjacent equipment address list. Therefore, the target media access control address of the target equipment is determined through the peer-to-peer network group information carried by the target broadcast information, the adjacent equipment address list is obtained, the internet protocol address corresponding to the target media access control address is searched in the adjacent equipment address list according to the target media access control address of the target equipment, and the obtaining efficiency of the internet protocol address of the target equipment is improved.
The method described in the above examples is further illustrated in detail below by way of example.
In this embodiment, the information acquisition apparatus will be described by taking an example in which it is specifically integrated in a computer device. The information acquisition method takes a terminal as an execution main body. Specifically, please refer to fig. 3, and fig. 3 is a schematic flowchart illustrating an information obtaining method according to an embodiment of the present application.
For a better description of the embodiments of the present application, please refer to fig. 3 and fig. 4 together. As shown in fig. 4, fig. 4 is another schematic flow chart of the information obtaining method according to the embodiment of the present application. The specific process is as follows:
in step 201, the terminal searches for a target device, establishes peer-to-peer network connection with the target device, and obtains target network information carried by broadcast information by calling a network information request function when receiving the target broadcast information.
The terminal can create a peer-to-peer NETWORK connection service in a system service, start the peer-to-peer NETWORK connection service, and further search surrounding P2P devices through a startSearch () function of wifi 2pSettings, so as to establish peer-to-peer NETWORK connection with the searched target device, and at the same time, register a broadcast receiver, and further acquire information of peer-to-peer NETWORK connection state change by monitoring broadcast information, where the broadcast information includes target broadcast information carrying the peer-to-peer NETWORK connection state information, and in order to ensure accuracy of acquiring peer-to-peer NETWORK group information, it may be determined whether the peer-to-peer device is successfully connected before acquiring the peer-to-peer NETWORK group information, and specifically, when receiving the target broadcast information, the target NETWORK information carried by the broadcast information may be acquired by calling a NETWORK information request function wifi 2pm manager.
In step 202, the terminal detects the state information of the peer-to-peer network connection according to the target network information, and acquires the peer-to-peer network group information carried by the target broadcast information when the state of the peer-to-peer network connection is a connection state.
Specifically, the target NETWORK information (NetworkInfo) attached to the target broadcast information may be obtained through a wifip2pmanager.extra _ NETWORK _ INFO request, and it may be determined, through an isConnected () function of the NetworkInfo, whether the currently received target broadcast information is sent successfully by a device in the peer-to-peer NETWORK group or when the device is disconnected. When the target broadcast information is successfully sent out by the equipment in the peer-to-peer network group, the peer-to-peer equipment is indicated to be successfully connected, and then the peer-to-peer network group information is obtained.
In step 203, the terminal reads the peer-to-peer network group information and determines the group role of the target device.
The terminal can read the peer-to-peer network group information by calling a role judgment function to obtain calling information, and determine the group role of the target device according to the calling information, specifically, the group role of the local device, namely, the isGroupOwner () function of the WifiP2pGroup, can be judged by executing the role judgment function, so that the calling information is received, when the calling information is "True", the local device is indicated to be the group owner role, and the peer device, namely, the group role of the target device is the group user role; when the call information is "False", it indicates that the local device is in the group user role, and the group role of the target device is in the group owner role.
In step 204, the terminal obtains the peer-to-peer network device information of the target device by calling a first obtaining function when the role type of the target device is the group owner role, and obtains the peer-to-peer network device information of the target device by calling a second obtaining function when the role type of the target device is the group user role.
When the role type of the target device is the group owner role, the terminal may obtain the peer-to-peer network device information (WifiP2pDevice) of the target device by calling a first obtaining function, that is, the getOwner () function of the WifiP2pGroup, and when the role type of the target device is the group user role, obtain the peer-to-peer network device information (WifiP2pDevice) of the target device by calling a second obtaining function, that is, the getClientList () function of the WifiP2 pGroup.
In step 205, the terminal queries the device address information in the peer-to-peer network device information to obtain the target mac address of the target device.
Wherein, the terminal inquires the device address information (DeviceAddress) in the peer-to-peer network device information to obtain the target media access control address of the target device.
In step 206, a target internet protocol command of the network configuration tool is executed, generating a list of neighboring device addresses.
The terminal may generate the neighboring device address list by executing a target internet protocol command of a network configuration tool of the Linux operating system or the Linux-like operating system. The neighboring device address list includes a mapping between the mac address and the ip address of the device.
In step 207, the terminal searches for each mac address in the neighbor address list according to the target mac address.
The mapping relation between the MAC address of the device and the IP address can be included in the neighboring device address list, and the IP address corresponding to the target MAC address can be searched in the neighboring device address list. Specifically, the terminal searches each MAC address item in the neighboring device address list according to the target MAC address.
In step 208, when the target mac address corresponding to the target mac address is searched, the terminal obtains the ip address of the row where the target mac address is located.
When a target media access control address item corresponding to the target media access control address is searched, the terminal acquires an internet protocol address in a row where the target media access control address item is located, wherein the internet protocol address is an internet protocol address of the target device.
In one embodiment, after obtaining the neighbor address list, in order to facilitate searching the content in the list and thus increase the searching speed, the neighbor address list may be sorted, specifically, since the length of the MAC address is 48 bits (i.e. 6 bytes), where the first 3 bytes represent the number of the network hardware manufacturer, and therefore, each row of address information in the neighbor address list may be sorted according to the network hardware manufacturer number of the MAC address. Furthermore, the target MAC address corresponding to the target MAC address is searched in the MAC address set by acquiring the target MAC address number in the target MAC address, and acquiring the MAC address set of the neighboring device address list, wherein the MAC address is the same as the target MAC address.
As can be seen from the above, in the embodiment of the present application, a terminal searches for a target device, establishes peer-to-peer network connection with the target device, and obtains target network information carried by broadcast information by calling a network information request function when receiving the target broadcast information; the terminal detects the state information of the peer-to-peer network connection according to the target network information, and when the state of the peer-to-peer network connection is a connection state, the terminal acquires peer-to-peer network group information carried by the target broadcast information; the terminal reads the peer-to-peer network group information and determines the group role of the target device; when the role type of the target equipment is the role of a group owner, the terminal acquires the peer-to-peer network equipment information of the target equipment by calling a first acquisition function, and when the role type of the target equipment is the role of a group user, the terminal acquires the peer-to-peer network equipment information of the target equipment by calling a second acquisition function; the terminal inquires the device address information in the peer-to-peer network device information to obtain the target media access control address of the target device; executing a target internet protocol command of a network configuration tool to generate a neighboring device address list; the terminal searches each MAC address item in the neighboring equipment address list according to the target MAC address; when the target MAC address item corresponding to the target MAC address is searched, the IP address of the row where the target MAC address item is located is obtained. Therefore, the target media access control address of the target equipment is determined through the peer-to-peer network group information carried by the target broadcast information, the adjacent equipment address list is obtained, the internet protocol address corresponding to the target media access control address is searched in the adjacent equipment address list according to the target media access control address of the target equipment, and the obtaining efficiency of the internet protocol address of the target equipment is improved.
In order to better implement the above method, an embodiment of the present invention further provides an information acquisition apparatus, which may be integrated in a computer device, and the computer device may be a terminal.
For example, as shown in fig. 5, for a schematic structural diagram of an information acquisition apparatus provided in an embodiment of the present application, the information acquisition apparatus may include a search unit 301, a receiving unit 302, a determining unit 303, an acquiring unit 304, and a searching unit 305, as follows:
a searching unit 301, configured to search for a target device and establish peer-to-peer network connection with the target device;
a receiving unit 302, configured to receive target broadcast information, and obtain peer-to-peer network group information according to the target broadcast information;
a determining unit 303, configured to determine a mac address of the target device according to the peer-to-peer network group information;
an obtaining unit 304, configured to obtain a neighboring device address list;
a searching unit 305, configured to search for an internet protocol address corresponding to the target mac address based on the neighboring device address list.
In one embodiment, the lookup unit 305 includes:
a first searching subunit, configured to search each mac address entry in the neighboring device address list according to the target mac address;
the first obtaining subunit is configured to, when a target mac address entry corresponding to the target mac address is searched, obtain an ip address in a row of the target mac address entry, where the ip address is an ip address of the target device.
In an embodiment, the information acquiring apparatus further includes:
the arrangement unit is used for classifying and arranging each row of address information in the adjacent equipment address list according to the network hardware manufacturer number of the MAC address.
In one embodiment, the lookup unit 305 includes:
a determining subunit, configured to determine a target network hardware manufacturer number in the target mac address;
a second obtaining subunit, configured to obtain a mac address item set, where a network hardware manufacturer number in the neighboring device address list is the same as the target network hardware manufacturer number;
a second searching subunit, configured to search the mac address entry set for a target mac address entry corresponding to the target mac address;
a third obtaining subunit, configured to obtain an internet protocol address of a row in which the target mac address entry is located.
In an embodiment, the determining unit 303 includes:
a reading subunit, configured to read the peer-to-peer network group information, and determine a group role of the target device;
a fourth obtaining unit, configured to obtain peer-to-peer network device information of the target device according to the group role;
and the inquiring subunit is used for inquiring the device address information in the peer-to-peer network device information to obtain the target media access control address of the target device.
In an embodiment, the fourth obtaining unit is configured to:
when the role type of the target equipment is the role of the group owner, acquiring the peer-to-peer network equipment information of the target equipment by calling a first acquisition function;
and when the role type of the target equipment is the group user role, acquiring the peer-to-peer network equipment information of the target equipment by calling a second acquisition function.
In one embodiment, the receiving unit 302 includes:
the calling subunit is used for obtaining the target network information carried by the broadcast information by calling a network information request function when the target broadcast information is received;
a detecting subunit, configured to detect status information of the peer-to-peer network connection according to the target network information;
and the fifth acquiring subunit is configured to acquire the peer-to-peer network group information carried by the target broadcast information when the peer-to-peer network connection state is the connection state.
In an embodiment, the obtaining unit 304 includes:
and the execution subunit is used for executing the target Internet protocol command of the network configuration tool and generating a neighboring device address list.
In a specific implementation, the above units may be implemented as independent entities, or may be combined arbitrarily to be implemented as the same or several entities, and the specific implementation of the above units may refer to the foregoing method embodiments, which are not described herein again.
As can be seen from the above, in the embodiment of the present application, the searching unit 301 searches for the target device, and establishes peer-to-peer network connection with the target device; the receiving unit 302 receives the target broadcast information and acquires peer-to-peer network group information according to the target broadcast information; the determining unit 303 determines the target mac address of the target device according to the peer-to-peer network group information; the obtaining unit 304 obtains a neighboring device address list, where the neighboring device address list includes a mapping relationship between a mac address and an ip address of a device; the lookup unit 305 looks up the ip address corresponding to the mac address based on the neighboring device address list. Therefore, the target media access control address of the target equipment is determined through the peer-to-peer network group information carried by the target broadcast information, the address list of the adjacent equipment is obtained, the internet protocol address corresponding to the target media access control address is searched in the address list of the adjacent equipment according to the target media access control address of the target equipment, and the efficiency of obtaining the internet protocol address of the target equipment is improved.
An embodiment of the present application further provides a computer device, as shown in fig. 6, which shows a schematic structural diagram of a computer device according to an embodiment of the present application, where the computer device may be a terminal, and specifically:
the computer device may include components such as a processor 401 of one or more processing cores, memory 402 of one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that the computer device configuration illustrated in FIG. 6 does not constitute a limitation of computer devices, and may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. Wherein:
the processor 401 is a control center of the computer device, connects various parts of the entire computer device using various interfaces and lines, and performs various functions of the computer device and processes data by running or executing software programs and/or modules stored in the memory 402 and calling data stored in the memory 402, thereby monitoring the computer device as a whole. Optionally, processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 401.
The memory 402 may be used to store software programs and modules, and the processor 401 executes various functional applications and information retrieval by operating the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to use of the computer device, and the like. Further, the memory 402 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 access to the memory 402.
The computer device further comprises a power supply 403 for supplying power to the various components, and preferably, the power supply 403 is logically connected to the processor 401 via a power management system, so that functions of managing charging, discharging, and power consumption are implemented via the power management system. The power supply 403 may also include any component of one or more dc or ac power sources, recharging systems, power failure detection circuitry, power converters or inverters, power status indicators, and the like.
The computer device may also include an input unit 404, the input unit 404 being operable to receive input numeric or character information and to generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
Although not shown, the computer device may further include a display unit and the like, which are not described in detail herein. Specifically, in this embodiment, the processor 401 in the computer device loads the executable file corresponding to the process of one or more application programs into the memory 402 according to the following instructions, and the processor 401 runs the application programs stored in the memory 402, thereby implementing various functions as follows:
searching a target device and establishing peer-to-peer network connection with the target device; receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information; determining a target MAC address of the target device based on the peer-to-peer network group information; acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address; and searching the internet protocol address corresponding to the target media access control address based on the adjacent equipment address list.
The above operations can be implemented in the foregoing embodiments, and are not described in detail herein. It should be noted that the computer device provided in the embodiment of the present application and the information obtaining method in the foregoing embodiment belong to the same concept, and specific implementation processes thereof are detailed in the foregoing method embodiment and are not described herein again.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer readable storage medium and loaded and executed by a processor.
To this end, the present application provides a storage medium, in which a plurality of instructions are stored, where the instructions can be loaded by a processor to execute the steps in any one of the information acquisition methods provided in the present application. For example, the instructions may perform the steps of:
searching a target device and establishing peer-to-peer network connection with the target device; receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information; determining a target MAC address of the target device based on the peer-to-peer network group information; acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address; and searching the internet protocol address corresponding to the target media access control address based on the adjacent equipment address list.
Wherein the storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Since the instructions stored in the storage medium may execute the steps in any information acquisition method provided in the embodiments of the present application, beneficial effects that can be achieved by any information acquisition method provided in the embodiments of the present application may be achieved, which are detailed in the foregoing embodiments and will not be described herein again.
According to an aspect of the application, there is provided, among other things, a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to cause the computer device to perform the method provided in the various alternative implementations provided by the embodiments described above.
The foregoing detailed description is directed to an information obtaining method, an information obtaining apparatus, and a storage medium provided in the embodiments of the present application, and specific examples are applied in the present application to explain the principles and implementations of the present application, and the descriptions of the foregoing embodiments are only used to help understand the methods and core ideas of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. An information acquisition method, comprising:
searching target equipment and establishing peer-to-peer network connection with the target equipment;
receiving target broadcast information, and acquiring peer-to-peer network group information according to the target broadcast information;
determining a target MAC address of the target device based on the peer-to-peer network group information;
acquiring a neighboring device address list, wherein the neighboring device address list comprises a mapping relation between a media access control address of a device and an internet protocol address;
and searching an internet protocol address corresponding to the target media access control address based on the adjacent equipment address list.
2. The information acquisition method as claimed in claim 1, wherein said searching for the internet protocol address corresponding to the target mac address based on the neighboring device address list comprises:
searching each MAC address item in the neighboring device address list according to the target MAC address;
when a target media access control address item corresponding to the target media access control address is searched, an internet protocol address in a row where the target media access control address item is located is obtained, and the internet protocol address is an internet protocol address of the target device.
3. The information acquisition method as claimed in claim 1, wherein before said searching for the internet protocol address corresponding to the target mac address based on the neighboring device address list, further comprises:
and classifying and arranging the address information of each row in the adjacent equipment address list according to the network hardware manufacturer number of the MAC address.
4. The information acquisition method as claimed in claim 3, wherein said searching for the internet protocol address corresponding to the target mac address based on the neighboring device address list comprises:
determining a target network hardware manufacturer number in the target MAC address;
acquiring a media access control address item set of which the network hardware manufacturer number is the same as the target network hardware manufacturer number in the adjacent equipment address list;
searching the set of MAC address entries for a target MAC address entry corresponding to the target MAC address;
obtaining the IP address of the line where the target MAC address item is located.
5. The information acquisition method as claimed in claim 1, wherein said determining a target mac address of the target device according to the peer-to-peer network group information comprises:
reading the peer-to-peer network group information and determining the group role of the target device;
acquiring peer-to-peer network equipment information of the target equipment according to the group role;
and inquiring equipment address information in the peer-to-peer network equipment information to obtain a target media access control address of the target equipment.
6. The information acquisition method according to claim 5, wherein the acquiring peer-to-peer network device information of the target device according to the group role comprises:
when the role type of the target equipment is a group owner role, acquiring peer-to-peer network equipment information of the target equipment by calling a first acquisition function;
and when the role type of the target equipment is the group user role, acquiring the peer-to-peer network equipment information of the target equipment by calling a second acquisition function.
7. The information acquisition method of claim 1, wherein the receiving target broadcast information and acquiring peer-to-peer network group information based on the target broadcast information comprises:
when target broadcast information is received, acquiring target network information carried by the broadcast information by calling a network information request function;
detecting the state information of the peer-to-peer network connection according to the target network information;
and when the connection state of the peer-to-peer network is a connection state, acquiring the peer-to-peer network group information carried by the target broadcast information.
8. The information acquisition method according to claim 1, wherein said acquiring the neighboring device address list includes:
and executing a target internet protocol command of the network configuration tool to generate a neighboring device address list.
9. An information acquisition apparatus characterized by comprising:
a search unit configured to search for a target device and establish a peer-to-peer network connection with the target device;
a receiving unit, configured to receive target broadcast information, and obtain peer-to-peer network group information according to the target broadcast information;
a determining unit, configured to determine a mac address of the target device according to the peer-to-peer network group information;
an acquisition unit configured to acquire a neighboring device address list;
and the searching unit is used for searching the Internet protocol address corresponding to the target media access control address based on the adjacent equipment address list.
10. A storage medium storing a plurality of instructions, the instructions being adapted to be loaded by a processor to perform the steps of the information acquisition method according to any one of claims 1 to 8.
CN202110642479.9A 2021-06-09 2021-06-09 Information acquisition method and device and storage medium Pending CN113490197A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110642479.9A CN113490197A (en) 2021-06-09 2021-06-09 Information acquisition method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110642479.9A CN113490197A (en) 2021-06-09 2021-06-09 Information acquisition method and device and storage medium

Publications (1)

Publication Number Publication Date
CN113490197A true CN113490197A (en) 2021-10-08

Family

ID=77934997

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110642479.9A Pending CN113490197A (en) 2021-06-09 2021-06-09 Information acquisition method and device and storage medium

Country Status (1)

Country Link
CN (1) CN113490197A (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170237704A1 (en) * 2016-02-16 2017-08-17 Le Holdings (Beijing) Co., Ltd. Addressing communication method and electronic device based on media access control address
CN110035133A (en) * 2018-01-12 2019-07-19 珠海全志科技股份有限公司 The method and apparatus of peer device IP address is obtained in Android WiFi-Direct connection

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170237704A1 (en) * 2016-02-16 2017-08-17 Le Holdings (Beijing) Co., Ltd. Addressing communication method and electronic device based on media access control address
CN110035133A (en) * 2018-01-12 2019-07-19 珠海全志科技股份有限公司 The method and apparatus of peer device IP address is obtained in Android WiFi-Direct connection

Similar Documents

Publication Publication Date Title
CN110113441B (en) Computer equipment, system and method for realizing load balance
CN112333298B (en) Message transmission method and device, computer equipment and storage medium
CN106559451B (en) User migration method and device
CN112040030B (en) Message transmission method and device, computer equipment and storage medium
CN111404753B (en) Flat network configuration method, computer equipment and storage medium
CN113242293B (en) UPF equipment, data processing and capacity expansion method and device
CN112333017B (en) Service configuration method, device, equipment and storage medium
EP3451592B1 (en) Packet transmission between vxlan domains
US20160277237A1 (en) Network bootstrapping for a distributed storage system
EP4318251A1 (en) Data access system and method, and device and network card
US8358648B1 (en) Allocating socket ranges to increase address space
CN112040029B (en) NAT conversion method, device, computer equipment and storage medium
CN110636149B (en) Remote access method, device, router and storage medium
CN112689029A (en) Method, device and equipment for acquiring IP address of group user
CN113490197A (en) Information acquisition method and device and storage medium
CN109005071B (en) Decision deployment method and scheduling equipment
WO2023030178A1 (en) Communication method based on user-mode protocol stack, and corresponding apparatus
CN115987915A (en) Message forwarding method for virtual switch and related equipment
CN110688237A (en) Method for forwarding message, intermediate device and computer device
WO2019076068A1 (en) Data transmission method, server, unloading card, and storage medium
CN113630300B (en) Method and node for message transmission
CN110110004B (en) Data operation method, device and storage medium
CN111464664B (en) Interactive access system, method and device of multi-access equipment and access equipment
TW202020684A (en) Method, transceiver engine and system for implementing collective storage space
WO2024001549A1 (en) Address configuration method and electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20211008

RJ01 Rejection of invention patent application after publication