Cross-network-segment equipment searching and communication method
Technical Field
The invention relates to a method for searching and communicating cross-network-segment equipment.
Background
With the rapid development of IP networks, it is becoming more and more common to build monitoring systems using IP networks. For example, in a security monitoring system, each monitoring device may be in a different network segment. Under the condition, each monitoring device can be automatically and quickly searched and found, the online information and the IP information of the device can be paid attention to in real time, effective communication with the device can be carried out, and the like, and the method is very important for users.
In the prior art, a Universal Plug and Play (UpnP) search device is adopted, and UpnP is a set of protocol framework aiming at realizing mutual seamless connection of various devices in a home network and a company network and simplifying related network realization. The UPnP protocol framework implements a device discovery function by an SSDP protocol (simple service discovery protocol). The control node unit searches the plug-and-play device in a multicast mode, and the plug-and-play device replies the search request of the control node unit in a unicast mode. However, the UpnP method cannot implement the search of the cross-segment device, and when the IP addresses conflict, the device cannot be accurately found.
In addition to UpnP, in the prior art, the WS-Discovery of ONVIF is also used for device Discovery, which sends a SOAP broadcast packet with a broadcast address of 239.255.255.255 and a port of 3702, but this method cannot implement cross-network segment communication.
In the prior art, some other broadcasting methods except the above method exist for device discovery, but generally, information provided after searching for a device is not complete, and information communication after IP address collision cannot be performed.
Disclosure of Invention
In order to overcome the defects of the prior art, the invention provides a cross-network segment equipment searching and communication method, which supports cross-network segment equipment discovery and cross-network segment communication, and can carry out communication even if IP addresses conflict.
The technical scheme adopted by the invention for solving the technical problems is as follows:
the invention provides a method for searching cross-network-segment equipment, which comprises the following steps:
defining a data packet structure;
the search end sends a detection data packet to the equipment end;
when the equipment end receives the detection data packet, a broadcast packet of a data link layer is sent to the search end, and the packet is defined as an information data packet;
the search end identifies the information data packet, matches the identification information of the packet, the type of the packet, and the like, and records the MAC address of the device.
As a further preferred embodiment, the broadcast packet address is 0 xFFFFFF.
As a further preferred embodiment, when the device side sends an information data packet to the search side, the device side sends the information data packet to the search side every 30 seconds.
As a further preferred implementation, the data packet structure includes MAC address information, identification information, and the like.
As a further preferred embodiment, the method for searching for devices across network segments further includes a communication process, which specifically includes the following steps:
after the searching terminal searches the equipment, the equipment terminal sends a control data packet to the searching terminal by taking the obtained equipment MAC address as the unique identification of communication, and the searching terminal modifies the network information of the equipment.
As a further preferred embodiment, after the search end receives the control data packet, the user name and the password need to be input, and the network information of the device can be modified after the verification is passed.
As a further preferred embodiment, further comprising: and the search end judges whether the modification is successful.
As a further preferred embodiment, the operation of the search end for judging whether the modification is successful specifically includes: after the search end carries out the operation of modifying the information, the equipment end returns an information data packet after the information modification to the search end, then the search end compares a return value with a modified value, and if the return value is the same as the modified value, the modification is successful; if the return value is different from the modification value, the modification is failed, and the search end carries out information modification operation on the equipment again.
The invention has the following positive effects:
1. the traditional equipment search is based on network layer to search and communicate, and the invention is based on data link layer in network seven-layer protocol to search and communicate.
2. The invention takes the MAC address as the unique identification, because the MAC address is the unique identification of all network devices, the device which is subject to IP conflict can be distinguished when the communication is carried out in a data link layer.
3. The data packet of the invention is provided with a special identification bit, and further refines the communication protocol.
In summary, the method of the present invention supports cross-segment device discovery; meanwhile, cross-network communication is supported, and communication can be performed even if IP addresses conflict; the information can be customized, and complete information is attached when equipment is searched.
Drawings
FIG. 1 is a schematic diagram of the connection of various devices according to an embodiment of the present invention;
FIG. 2 is a diagram of a packet structure according to an embodiment of the present invention;
FIG. 3 is a diagram of a detection packet according to an embodiment of the present invention;
FIG. 4 is an information packet according to an embodiment of the present invention;
fig. 5 is a control packet according to an embodiment of the present invention.
Detailed Description
Preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
Fig. 1 shows connection diagrams of respective devices, and a preferred embodiment of the present invention provides a method for searching devices across network segments, including the following steps (see fig. 2 to 5):
defining a data packet structure, said data packet structure being as shown in fig. 2;
the search end, i.e. the personal computer, sends a detection data packet to the equipment end, i.e. the network camera, as shown in fig. 3;
when the device side receives the detection data packet, a broadcast packet with an address of 0 xfffffff data link layer is sent to the search side, and the packet is defined as an information data packet, as shown in fig. 4; when the equipment end sends the information data packet to the search end, the equipment end sends the information data packet to the search end every 30 seconds, and the operation effectively prevents the occurrence of packet loss.
The search end identifies the information data packet, matches the identification information of the packet, the type of the packet, and the like, and records the MAC address of the device.
The method for searching the devices across the network segments further comprises a communication process, which comprises the following specific steps:
after the searching terminal searches the equipment, the equipment terminal sends a control data packet to the searching terminal by taking the obtained equipment MAC address as a unique communication identifier, and the searching terminal modifies the network information of the equipment as shown in figure 5;
and the search end judges whether the modification is successful.
After receiving the control data packet, the search end needs to input a user name and a password, and the network information of the equipment can be modified after the user name and the password pass the verification.
The data packet structure specifically comprises:
(1)0 to 5 data bits: the destination MAC address is sent. Such as 0XFFFFFF, for example, as a broadcast address.
(2)6 to 11 data bits: the MAC address of the sending end is used for returning the identification of the opposite side.
(3)12 to 13 data bits: the data filtering and identifying functions are realized, and the receiving end only recognizes the data packet as 0X 89.
(4)14 to 18 data bits: the data identification bits are specially identified to belong to company series data packets.
(5)19 data bits: the type of the packet is identified (search for 0, modification for 1, etc.).
(6)20 to 25 data bits: and the MAC address filter is used for specifying the MAC address needing to be modified when the device side has a plurality of MAC addresses. If two MACs, Lan and WIFI, need to be distinguished.
(7)26 to 245 data bits: data information for transmission includes: IP address, subnet mask, gateway, user name, password and other information, support extension.
(8)246 bits to 253 data bits: is a checksum.
The operation of the search end for judging whether the modification is successful is specifically as follows: after the search end carries out the operation of modifying the information, the equipment end returns an information data packet after the information modification to the search end, then the search end compares a return value with a modified value, and if the return value is the same as the modified value, the modification is successful; if the return value is different from the modification value, the modification is failed, and the search end carries out information modification operation on the equipment again.
The above embodiments are only preferred embodiments of the present invention, and it should be understood that the above embodiments are only for assisting understanding of the method and the core idea of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalents and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.