Service detection method and device, electronic equipment and storage medium
By sending the first discovery message carrying the survival time to the preset public network device and detecting the target network segment, the problem that the initiator cannot detect the receiver's IP address in different local area networks is solved, and communication between the initiator and the receiver is realized.
Patent Information
- Application Number
- CN202311218549.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-20
- Publication Date
- 2025-03-28
AI Technical Summary
When the initiator and the receiver are in different local area networks, the initiator cannot detect the receiver's IP address through broadcast or multicast, resulting in the inability to establish and communicate between the initiator and the receiver.
By sending a first discovery message carrying a survival time to the preset public network device, the target network segment to which the source address of the timeout message belongs, and the second discovery message is sent to the devices corresponding to multiple addresses in the network segment to detect and obtain the address of the receiver.
It is realized that when the initiator and the receiver are in different local area networks, the initiator can know the receiver's address, thereby realizing communication between the initiator and the receiver.
Smart Images

Figure CN119728497A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network communication technology, and in particular to a service detection method, device, electronic device and storage medium. Background Art
[0002] In the Internet, when an initiator needs to communicate with a receiver, it needs to know the receiver's IP (Internet Protocol) address so that the initiator and the receiver can establish a connection and achieve communication. For example, in a CS (client-server) architecture, the client needs to know the server's IP address so that the client can establish a connection with the server and achieve communication between the client and the server.
[0003] If the initiator and the receiver are in the same LAN, the initiator can detect the IP address of the receiver in the LAN by broadcasting or multicasting. However, the initiator and the receiver may be in different LANs, and the initiator cannot detect the IP address of the receiver by broadcasting or multicasting, and cannot establish a connection between the initiator and the receiver, and cannot achieve communication between the initiator and the receiver. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a service detection method, device, electronic device and storage medium, so that when the initiator and the receiver are in different local area networks, the initiator can obtain the address of the receiver, thereby realizing communication between the initiator and the receiver. The specific technical solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides a service detection method, which is applied to a first device, and the method includes:
[0006] Sending a first discovery message to a preset public network device, wherein the first discovery message carries a lifetime, so that a second device that receives the first discovery message sends a timeout message to the first device when the lifetime times out;
[0007] Obtain the target network segment to which the source address of the timeout message belongs;
[0008] Sending a second discovery message to devices corresponding to multiple addresses in the target network segment, where the destination port of the second discovery message is a port of a third device providing communication services;
[0009] If a discovery response message corresponding to the second discovery message is received, the source address of the discovery response message is used as the address of the third device.
[0010] Optionally, the method further includes:
[0011] If the discovery response message corresponding to the second discovery message is not received, the lifetime is increased by a preset time length, and the process returns to the step of sending the first discovery message to the preset public network device.
[0012] Optionally, before returning to execute the step of sending the first discovery message to the preset public network device, the method further includes:
[0013] Determine whether the number of detections reaches a preset number, where the number of detections is the number of times the first device sends the first discovery message;
[0014] If not, return to execute the step of sending the first discovery message to the preset public network device.
[0015] Optionally, before the step of obtaining the target network segment to which the source address of the timeout message belongs, the method further includes:
[0016] Determine whether the source address of the timeout message is a private address;
[0017] If so, execute the step of obtaining the target network segment to which the source address of the timeout message belongs.
[0018] Optionally, the method further includes:
[0019] Broadcasting a detection message in the local area network to which the first device belongs, where the destination port of the detection message is a port of the third device;
[0020] If a probe response message corresponding to the probe message fed back by the third device is received, the source address of the probe response message is used as the address of the third device;
[0021] If the detection response message corresponding to the detection message fed back by the third device is not received, the step of sending the first discovery message to the preset public network device is executed.
[0022] Optionally, after obtaining the address of the third device, the method further includes:
[0023] According to the address of the third device, a connection request message is sent to the third device, so that the third device establishes a connection with the first device, and the destination port of the connection request message is a port of the third device.
[0024] Optionally, the first discovery message is a message of a connectionless protocol, and a destination port of the first discovery message is an unoccupied port.
[0025] In a second aspect, an embodiment of the present application provides a service detection device, which is applied to a first device, and the device includes:
[0026] A first sending module, configured to send a first discovery message to a preset public network device, wherein the first discovery message carries a lifetime, so that a second device that receives the first discovery message sends a timeout message to the first device when the lifetime times out;
[0027] A target network segment acquisition module, used to acquire the target network segment to which the source address of the timeout message belongs;
[0028] A second sending module, used to send a second discovery message to devices corresponding to multiple addresses in the target network segment, wherein the destination port of the second discovery message is a port of a third device providing communication services;
[0029] The first determining module is configured to use, if a discovery response message corresponding to the second discovery message is received, a source address of the discovery response message as the address of the third device.
[0030] Optionally, the device further comprises:
[0031] The first return module is used to increase the survival time by a preset time length if the discovery response message corresponding to the second discovery message is not received, and return to execute the step of sending the first discovery message to the preset public network device.
[0032] Optionally, the device further comprises:
[0033] A first judgment module, used for judging whether the number of detections reaches a preset number of times before returning to execute the step of sending the first discovery message to the preset public network device, where the number of detections is the number of times the first device sends the first discovery message;
[0034] The second returning module is used to return to the step of sending the first discovery message to the preset public network device if no.
[0035] Optionally, the device further comprises:
[0036] A second judgment module is used to judge whether the source address of the timeout message is a private address before the step of obtaining the target network segment to which the source address of the timeout message belongs;
[0037] The first execution module is used to execute the step of obtaining the target network segment to which the source address of the timeout message belongs if yes.
[0038] Optionally, the device further comprises:
[0039] A detection message broadcasting module, used for broadcasting a detection message in the local area network to which the first device belongs, wherein the destination port of the detection message is a port of the third device;
[0040] A second determining module is configured to use, if a probe response message corresponding to the probe message fed back by the third device is received, a source address of the probe response message as the address of the third device;
[0041] The second execution module is used to execute the step of sending the first discovery message to the preset public network device if the detection response message corresponding to the detection message fed back by the third device is not received.
[0042] Optionally, the device further comprises:
[0043] The third sending module is used to send a connection request message to the third device according to the address of the third device after obtaining the address of the third device, so that the third device establishes a connection with the first device, and the destination port of the connection request message is the port of the third device.
[0044] Optionally, the first discovery message is a message of a connectionless protocol, and a destination port of the first discovery message is an unoccupied port.
[0045] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0046] Memory, used to store computer programs;
[0047] The processor is used to implement any method described in the first aspect when executing a program stored in the memory.
[0048] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any method described in the first aspect is implemented.
[0049] Beneficial effects of the embodiments of the present application:
[0050] In the solution provided by the embodiment of the present application, in theory, the third device that provides a server for the first device is closer to the first device than the public network device. The first device sends a first discovery message carrying a lifetime to the preset public network device. In this way, when the first discovery message does not reach the preset public network device, the lifetime carried by the first discovery message times out. Then, the second device that sends the timeout message to the first device, its address (source address of the timeout message) belongs to a network segment that is likely to be the network segment to which the address of the third device belongs. Therefore, the first device can detect the third device in the network segment to which the address of the second device belongs, and obtain the address of the third device. This enables the initiator to know the address of the receiver when the initiator and the receiver are in different local area networks, thereby achieving communication between the initiator and the receiver.
[0051] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0053] Figure 1 This is a schematic diagram of the first structure where the initiator and the receiver are in different local areas;
[0054] Figure 2 This is a schematic diagram of the second structure where the initiator and the receiver are in different local areas;
[0055] Figure 3 A flow chart of a service detection method provided in an embodiment of the present application;
[0056] Figure 4 A specific flow chart of service detection within a local area network provided in an embodiment of the present application;
[0057] Figure 5 A specific flow chart of the service detection method provided in the embodiment of the present application;
[0058] Figure 6 A structural diagram for performing service detection using the service detection method provided in an embodiment of the present application;
[0059] Figure 7 A schematic diagram of the structure of a service detection device provided in an embodiment of the present application;
[0060] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field based on the present application belong to the scope of protection of the present application.
[0062] With the development of the Internet, devices in different local area networks can be connected to each other to achieve information exchange and resource sharing. If the initiator and the receiver need to communicate, the initiator needs to know the IP address of the receiver so that the initiator can send a connection request to the receiver to communicate with the receiver when the connection is established.
[0063] For example, in the CS architecture, if the client and the server are in different local area networks, the CAPWAP (Control And Provisioning of Wireless Access Points) protocol can be used through the DNS (Domain Name System) or DHCP (Dynamic Host Configuration Protocol) option 43 field to inform the client of the IP address of the server to which it is to connect. In this way, the client can establish a connection with the server and communicate with the server after knowing the IP address of the server.
[0064] For example, in Figure 1 In the network architecture shown, AP (Wireless Access Point) needs to establish a connection with AC (Wireless Access Control). APs include AP1, AP2, AP3, AP4, AP5, and AP6. AP1 to AP3 are connected to Router 1, AP4 to AP6 are connected to Router 2, Router 1, Router 2 are connected to Router 3, and Router 3 is connected to AC. In this network architecture, AP1 to AP6 and AC are in different LANs. If AP1 needs to communicate with AC, the option 43 field of DHCP needs to be configured on Router 1 so that AP1 can obtain the IP address of AC and establish a connection with AC. If AP4 needs to communicate with AC, the option 43 field of DHCP needs to be configured on Router 2 so that AP4 can obtain the IP address of AC and establish a connection with AC.
[0065] For example, in Figure 2In the home network shown, multiple IPCs (IP Cameras) need to establish connections with NAS (Network Attached Storage) or NVR (Network Video Recorder) to achieve associated streaming. IPCs include IPC1, IPC2, IPC3, and IPC4. IPC1 and IPC2 are connected to router 1, IPC3 and IPC4 are connected to router 2, router 1, router 2 are connected to router 3, and router 3 is connected to NAS / NVR. In this home network, NAS / NVR is deployed in the upper-level network of IPC, and IPC1 to IPC4 are in different LANs from NAS / NVR. If IPC1 needs to establish a connection with NAS / NVR, it is necessary to configure the option 43 field of DHCP on router 1 so that IPC1 can obtain the IP address of NAS / NVR and establish a connection with NAS / NVR.
[0066] However, since some routers used in the network architecture do not support the function of configuring the option 43 field, the client cannot obtain the IP address of the server, resulting in the client and the server being unable to establish a connection and communicate across the LAN.
[0067] In order to enable the initiator to detect the address of the receiver when the initiator and the receiver are in different local area networks, so that the initiator and the receiver can establish a connection and achieve communication, the embodiments of the present application provide a service detection method, device, electronic device, computer-readable storage medium and computer program product. First, a service detection method provided by the embodiments of the present application is introduced.
[0068] like Figure 3 As shown, a service detection method is applied to a first device, and the method includes:
[0069] S301, sending a first discovery message to a preset public network device; the first discovery message carries a lifetime, so that a second device that receives the first discovery message sends a timeout message to the first device when the lifetime times out;
[0070] S302, obtaining the target network segment to which the source address of the timeout message belongs;
[0071] S303, sending a second discovery message to devices corresponding to multiple addresses in the target network segment; the destination port of the second discovery message is a port of a third device providing communication services;
[0072] S304: If a discovery response message corresponding to the second discovery message is received, use the source address of the discovery response message as the address of the third device.
[0073] It can be seen that in the scheme provided in the embodiment of the present application, it is applied to the first device, and the first device can send a first discovery message to a preset public network device, and the first discovery message carries a survival time, so that when the survival time expires, the second device that receives the first discovery message sends a timeout message to the first device, obtains the target network segment to which the source address of the timeout message belongs, and sends a second discovery message to the devices corresponding to multiple addresses in the target network segment. The destination port of the second discovery message is the port of the third device that provides communication services. If a discovery response message corresponding to the second discovery message is received, the source address of the discovery response message is used as the address of the third device. In theory, relative to the public network device, the third device that provides a server for the first device is closer to the first device. The first device sends a first discovery message carrying a survival time to the preset public network device. In this way, when the first discovery message does not reach the preset public network device, the survival time carried by the first discovery message expires, then the second device that sends the timeout message to the first device, its address (source address of the timeout message) belongs to the network segment is likely to be the network segment to which the address of the third device belongs. Therefore, the first device can detect the third device in the network segment to which the address of the second device belongs, and obtain the address of the third device. This enables the initiator to know the address of the receiver when the initiator and the receiver are in different local area networks, thereby realizing communication between the initiator and the receiver.
[0074] In step S301, the first device may send a first discovery message to a preset public network device. The first device may be a client in the above-mentioned CS architecture, and the client may be a computer, a mobile phone, an AP, an IPC, etc. The preset public network device may be a server of a well-known website, and the address of the preset public network device may be a class A address or a class B address. The second device may be a device with specific communication functions such as a router or a switch.
[0075] The first discovery message carries a lifetime. When the lifetime time expires, the second device that receives the first discovery message sends a timeout message to the first device. The lifetime is the survival time of the first discovery message. Specifically, in the process of the first discovery message being transmitted from the first device to the preset public network device, the lifetime will be reduced by a certain period of time each time it passes through a route. Then, when the lifetime is reduced to less than or equal to 0 (when the lifetime times out), the first discovery message will be discarded. When the first discovery message is discarded, the second device that receives the first discovery message will send a timeout message to the first device. Among them, the initial value of the lifetime can be set to 2, and can also be set according to actual conditions, and is not specifically limited here.
[0076] As an implementation method, the first discovery message may be a message of a connectionless protocol. That is, the first device only needs to send the first discovery message to test whether the preset public network device is reachable without establishing a connection with the recipient (i.e., the preset public network device). Exemplarily, the message of the connectionless protocol may be a UDP (User Datagram Protocol) message, an ICMP (Internet Control Message Protocol) message, or the like. For example, if the first discovery message is an ICMP message, then an echo request message may be sent using the ping command.
[0077] If the first discovery message is sent to an occupied port, it will be processed by the application that has occupied the port, so that the second device will not send a timeout message to the first device. Therefore, as an implementation method, the destination port of the first discovery message is an unoccupied port. For example, the destination port can be a port greater than 40000, which is not specifically limited here.
[0078] When the survival time expires, the second device will send a timeout message to the first device, and the source address of the timeout message is the address of the second device. When the first device receives the timeout message, it can parse the timeout message to obtain the source address of the timeout message, that is, the address of the second device, and then execute step S302 to obtain the target network segment to which the source address of the timeout message belongs.
[0079] For example, Figure 1 As shown, the first device is AP1, and the lifetime is 2. AP1 sends a UDP message (the first discovery message) with a destination port of 45555 to the preset public network device. The UDP message will be reduced by 1 each time it passes through the route. When the UDP message reaches router 3, the lifetime is reduced to 0, and the UDP message will be discarded. Router 3 will send a timeout message (such as an ICMP timeout message) to AP1. AP1 receives the timeout message, parses the timeout message, and obtains the source address of the timeout message (the IP address of router 3), such as 192.166.2.2. Then, it can be obtained that the target network segment to which the source address of the timeout message belongs is 192.166.2.*, that is, 192.166.2.1 to 192.166.2.254.
[0080] In step S303, the first device may send a second discovery message to devices corresponding to multiple addresses in the target network segment, wherein the destination address of the second discovery message is an address in the target network segment, and the destination port of the second discovery message is a port of a third device providing communication services. The third device may be a server in the above-mentioned CS architecture. The number of second discovery messages sent by the first device is the same as the number of addresses in the target network segment. Since the message type is correlated with the port type, the type of the second discovery message depends on the port type of the third device.
[0081] For example, Figure 1 As shown, the third device is AC, and the port of AC is 5246, which is a CAPWAP protocol port, so the message type corresponding to this port is CAPWAP message. The target network segment obtained by AP1 is 192.166.2.1 to 192.166.2.254, then AP1 can send CAPWAP discovery messages to the devices corresponding to each address from 192.166.2.1 to 192.166.2.254.
[0082] In step S304, if the first device receives a discovery response message corresponding to the second discovery message, the source address of the discovery response message is used as the address of the third device. That is to say, when the address of the second device and the address of the third device belong to the same network segment, the first device sends the second discovery message to the device corresponding to each address in the network segment to which the second device belongs, and the third device can receive the second discovery message, and then send the corresponding discovery response message to the first device to respond to the first device. Then the first device can receive the discovery response message, parse the discovery response message, and obtain the source address of the discovery response message, that is, the address of the detected third device.
[0083] For example, following the example in the above step S303, since router 3 and AC are in the same local area network, that is, their addresses belong to the same network segment, AP1 sends a CAPWAP discovery message to the device corresponding to each address from 192.166.2.1 to 192.166.2.254, and AC can receive the CAPWAP discovery message to send a CAPWAP response message to AP1. Then AP1 can receive the CAPWAP response message and parse the CAPWAP response message to obtain the source address of the CAPWAP response message, that is, the detected address of the AC.
[0084] In the scheme of this embodiment, theoretically, the third device that provides a server for the first device is closer to the first device than the public network device. The first device sends a first discovery message carrying a lifetime to a preset public network device. In this way, when the first discovery message does not reach the preset public network device, the lifetime carried by the first discovery message times out. Then, the second device that sends a timeout message to the first device, its address (source address of the timeout message) belongs to a network segment that is likely to be the network segment to which the address of the third device belongs. Therefore, the first device can detect the third device in the network segment to which the address of the second device belongs, and obtain the address of the third device. This enables the initiator to know the address of the receiver when the initiator and the receiver are in different local area networks, thereby achieving communication between the initiator and the receiver.
[0085] As an implementation of the embodiment of the present application, the above method may also include:
[0086] If the discovery response message corresponding to the second discovery message is not received, the lifetime is increased by a preset time length, and the process returns to the step of sending the first discovery message to the preset public network device.
[0087] If the first device does not receive the discovery response message corresponding to the second discovery message, in one case, it may be because the lifetime carried by the first discovery message is shorter, so that the first discovery message passes through fewer routes, that is, the number of network segments passed by the first discovery message is smaller, so the length of the lifetime carried by the first discovery message can be increased.
[0088] If the first device does not receive the discovery response message corresponding to the second discovery message, the survival time can be increased by a preset time length, so that when the first device sends the first discovery message to the preset public network device, the first discovery message can pass through more routes and detect the third device that needs to establish communication in more network segments. Among them, the initial value of the survival time can be set to 2, and the preset time length can be 1, 2, etc., which are not specifically limited here.
[0089] For example, the initial value of the preset lifetime is 2, and the lifetime carried by the first discovery message sent by the first device for the first time is the preset lifetime, that is, 2. If the first device does not receive the discovery response message corresponding to the second discovery message, the lifetime can be increased by the preset duration 1, then the lifetime carried by the first discovery message sent by the first device for the second time is the lifetime increased by the preset duration, that is, 3.
[0090] It can be seen that in this embodiment, if the first device does not receive the discovery response message corresponding to the second discovery message, the survival time can be increased by the preset time length, and the step of sending the first discovery message to the preset public network device is returned, and the survival time carried by the resent first discovery message is increased by the preset time length. In this way, after the survival time of the first discovery message is increased, the first discovery message can pass through more routes during the process of being transmitted from the first device to the preset public network device, and then the third device can be detected in more network segments.
[0091] As an implementation manner of an embodiment of the present application, before returning to execute the step of sending the first discovery message to the preset public network device, the above method may further include:
[0092] Determine whether the number of detections reaches a preset number, where the number of detections is the number of times the first device sends the first discovery message;
[0093] If not, return to execute the step of sending the first discovery message to the preset public network device.
[0094] In one case, the first device may be connected to a third device that needs to establish communication across multiple local area networks. In this case, the first device may need to detect the third device multiple times.
[0095] In one embodiment, the number of detections can be preset, that is, the preset number of times. When the first device does not receive the discovery response message corresponding to the second discovery message, it is determined whether the number of detections reaches the preset number of times. If the number of detections does not reach the preset number of times, the first discovery message can be sent to the preset public network device again. At the same time, the lifetime carried by the first discovery message is the lifetime after the preset time length is increased. In this way, the first discovery message can continue to reach the upper-level route based on the route reached last time. If the number of detections reaches the preset number of times, the detection of the third device is terminated.
[0096] Among them, the number of detection times is the number of times the first device sends the first discovery message. As an implementation method, each time the first device sends the first discovery message, the number of transmissions can be recorded as the number of detection times. For example, the number of times the first device sends the first discovery message is 2, that is, the number of detections is 2, and the preset number is 3. If the first device does not receive the discovery response message corresponding to the second discovery message, and the number of detections 2 does not reach the preset number 3 at this time, then the first device can send the first discovery message to the preset public network device, and the survival time carried by the first discovery message is the survival time after the preset duration is increased.
[0097] Since the lifetime carried by the first discovery message will increase by the corresponding preset duration as the number of times it is sent increases, in one embodiment, the first device may first increase the lifetime by the preset duration if it has not received the discovery response message corresponding to the second discovery message, and then determine whether the number of detections has reached the preset number, so that if the number of detections has not reached the preset number, the first discovery message may be sent to the preset public network device. At this time, the lifetime carried by the first discovery message is the lifetime after the preset duration has been increased.
[0098] In another embodiment, the first device may first determine whether the number of detection times reaches the preset number if it has not received the discovery response message corresponding to the second discovery message, and then, if the number of detection times has not reached the preset number, increase the survival time by the preset duration, and then send the first discovery message to the preset public network device, so that the survival time carried by the first discovery message is the survival time after the preset duration is increased.
[0099] It can be seen that in this embodiment, the first device can determine whether the number of detections reaches the preset number of times, and the number of detections is the number of times the first device sends the first discovery message; if not, it returns to the step of sending the first discovery message to the preset public network device. In this way, the first device can perform multiple detections on the third device to ensure that the third device can be detected, and the number of detections is limited by the preset number of times, which can avoid the first device from detecting the third device infinitely, thereby reducing resource waste.
[0100] As an implementation manner of the embodiment of the present application, before the step of obtaining the target network segment to which the source address of the timeout message belongs, the method may further include:
[0101] Determine whether the source address of the timeout message is a private address;
[0102] If so, execute the step of obtaining the target network segment to which the source address of the timeout message belongs.
[0103] The first device ends the detection of the third device in two cases. One case is that the first device ends the detection of the third device when the detection times reach a preset number. The other case is that the first device ends the detection of the third device when the source address of the timeout message parsed by the first device is a public network address.
[0104] In one implementation, the first device may determine whether the source address of the timeout message is a private address. If the source address of the timeout message is a private address, the target network segment to which the source address of the timeout message belongs may be obtained to detect the third device in the target network segment. If the source address is a public network address, the detection of the third device may be terminated. The private address may be a Class C address, which is not specifically limited here.
[0105] It can be seen that in this embodiment, the first device can determine whether the timed-out source address is a private address, and if so, execute the step of obtaining the target network segment to which the source address of the timed-out message belongs. In this way, the first device can detect the third device in the network segment to which the address of the second device belongs, and obtain the address of the third device, so that when the initiator and the receiver are in different local area networks, the initiator can know the address of the receiver, thereby realizing communication between the initiator and the receiver.
[0106] As an implementation method of the present application, Figure 4 As shown, the above method may also include:
[0107] S401, broadcasting a detection message in the local area network to which the first device belongs; the destination port of the detection message is the port of the third device;
[0108] The first device and the third device providing communication services may be in different local area networks or in the same local area network. Therefore, before the first device sends the first discovery message to the preset public network device, the first device can broadcast a detection message in its local area network to detect the third device.
[0109] For example, the port of the third device is 5246, which is a CAPWAP protocol port, so the message type corresponding to the port is a CAPWAP message. The first device can send a CAPWAP broadcast detection message to the local area network to which it belongs.
[0110] S402: If a probe response message corresponding to the probe message fed back by the third device is received, use the source address of the probe response message as the address of the third device.
[0111] S403: If the detection response message corresponding to the detection message fed back by the third device is not received, the step of sending the first discovery message to the preset public network device is executed.
[0112] If the first device receives a detection response message corresponding to the detection message fed back by the third device, it means that the third device is detected, and the source address of the detection response message can be used as the address of the third device. If the first device does not receive a detection response message corresponding to the detection message fed back by the third device, it means that the first device and the third device are not in the same local area network, and the first device can continue to obtain other network segments to detect the third device, and then send a first discovery message to the preset public network device.
[0113] It can be seen that in this embodiment, the first device can broadcast a detection message in the local area network to which the first device belongs, and the destination port of the detection message is the port of the third device. If a detection response message corresponding to the detection message fed back by the third device is received, the source address of the detection response message is used as the address of the third device. If the detection response message corresponding to the detection message fed back by the third device is not received, the step of sending the first discovery message to the preset public network device is executed. In this way, the first device can detect the third device in the local area network to which it belongs, and if the third device is not detected, continue to obtain other network segments to detect the third device. Until the third device is detected and the address of the third device is obtained, this realizes that when the initiator and the receiver are in different local area networks, the initiator knows the address of the receiver, thereby realizing the communication between the initiator and the receiver.
[0114] As an implementation manner of the embodiment of the present application, after obtaining the address of the third device, the above method may further include:
[0115] According to the address of the third device, a connection request message is sent to the third device, so that the third device establishes a connection with the first device, and the destination port of the connection request message is a port of the third device.
[0116] The first device obtains the source address of the discovery response message, indicating that the third device has been detected, and the source address can be used as the address of the third device. In this way, the first device can send a connection request message with the destination port being the port of the third device to the third device according to the address of the third device, so as to establish a connection with the third device and realize communication.
[0117] It can be seen that in this embodiment, the first device can send a connection request message to the third device according to the address of the third device, so that the third device establishes a connection with the first device, and the destination port of the connection request message is the port of the third device. In this way, when the initiator and the receiver are in different local area networks, the initiator can know the address of the receiver, thereby realizing communication between the initiator and the receiver.
[0118] Figure 5 A specific flow chart of the service detection method provided in the embodiment of the present application. Take the client detecting the server as an example. Figure 5 The service detection method provided in the embodiment of the present application is introduced by way of example. Figure 5 As shown, the service detection method provided in the embodiment of the present application may include the following steps:
[0119] S501, broadcasting a detection message in the local area network to detect whether there is a server;
[0120] When the client needs to establish a connection with the server, it needs to know the IP address of the server. Since the client and the server may be in the same local area network or in different local area networks, the client can first detect the server in the local area network to which it belongs. In one embodiment, the client can broadcast a detection message in the local area network to detect whether there is a server in the local area network where the client is located.
[0121] S502, whether there is a server response; if yes, the detection ends, if not, execute step S503;
[0122] If the client receives a response from the server, it means that the client has detected the server in the LAN, and the detection can be ended. If the client does not receive a response from the server, it means that the client has not detected the server in the LAN, that is, there is no server in the LAN, and other network segments can be obtained to detect the server.
[0123] S503, set initial ttl_value=2;
[0124] The client can send a connectionless protocol message to the preset public network device, which can be a UDP message or an ICMP message, and the message carries the survival time. The initial value of the survival time is 2, that is, the initial ttl_value is set to 2.
[0125] S504, sending a UDP message or an ICMP message to a preset public network device, setting ttl=ttl_value, and the destination port is 45555;
[0126] When the client sends a UDP message or ICMP message to the preset public network device for the first time, the destination port is 45555, and the survival time carried in the message is the initial value 2 of the survival time, that is, ttl = ttl_value. Among them, the destination port is a port greater than 40000 to avoid the destination port being occupied.
[0127] If it is not the first time that the client sends a UDP message or ICMP message to the preset public network device, the survival time carried in the message is the survival time increased by the corresponding preset time. For example, the client sends a UDP message to the preset public network device for the second time, ttl_value = ttl_value + 1, that is, ttl_value = 3, then the survival time carried in the UDP message is 3.
[0128] S505, receiving a timeout message corresponding to a UDP message or an ICMP message, and parsing a source IP address of the timeout message;
[0129] According to the message forwarding principle, the survival time of a message will be reduced by 1 each time it passes through a router. If the survival time is less than or equal to 1, the message will be discarded, and the device that receives the message will send a timeout message corresponding to the message to the source device that sent the message. Therefore, when the survival time of a UDP message or ICMP message is less than or equal to 0, the client can receive the timeout message corresponding to the UDP message or ICMP message and resolve the source IP address of the timeout message.
[0130] S506, whether the source IP address of the timeout message is a private address; if yes, execute step S507, if not, end the detection;
[0131] If the client resolves the source IP address of the timeout message to a private address, the network segment to which the source IP address belongs can be obtained. If the client resolves the source IP address of the timeout message to a public network address, the detection can be terminated.
[0132] S507, traverse all IP addresses in the network segment to which the source IP address belongs, and send a message whose destination port is the port of the server to the device corresponding to each IP address;
[0133] After the client obtains the network segment to which the source IP address of the timeout message belongs, it can traverse all IP addresses in the network segment to which the source IP address belongs, and send a message with the destination port being the server's port to the device corresponding to each IP address to detect the server.
[0134] S508, whether there is a server response; if yes, end the detection; if not, execute step S509;
[0135] If the client receives a response message from the server, it can parse the source IP address of the response message to obtain the source IP address of the response message, and then use the source IP address of the response message as the address of the server to end the detection.
[0136] S509: Whether the number of detections exceeds the preset number; if yes, end the detection; if no, execute step S510;
[0137] If the client does not receive a response message from the server, it can determine whether the number of detections exceeds a preset number of detections to determine whether to continue to obtain other network segments to detect the server.
[0138] S510, set ttl_value=ttl_value+1.
[0139] If the number of detections by the client does not exceed the preset number of detections, the next network segment can be obtained to detect the server. In one embodiment, the survival time is increased by the preset duration, that is, ttl_value=ttl_value+1 can be set. In this way, when the client sends a UDP message or ICMP message to the preset public network device again, the survival time carried by the message becomes longer, and the number of routes that can be passed increases by 1, so that the next network segment can be obtained.
[0140] Specifically, in Figure 6 In the network architecture shown, AP1, AP2, and AP3 need to establish a connection with the AC, and the port of the AC is 5246. When AP1, AP2, and AP3 cannot determine whether they are in the same LAN as the AC, they can first broadcast a detection message to the LAN. That is, AP1 can send a CAPWAP broadcast detection message to the destination port 5246 in the LAN to detect whether there is an AC in the LAN.
[0141] Since the IP address of AP1 is 192.168.1.2 and the IP address of AC is 192.168.3.10, AP1 and AC are not in the same LAN. Therefore, AP1 cannot detect AC in the LAN, that is, it cannot receive the response message from AC. Then, AP1 can send an ICMP message with a destination port of 46666 and a destination IP address of the IP address of the well-known website A, and the survival time ttl carried in the ICMP message is 2.
[0142] When the ICMP message reaches Router 1, the ttl is reduced to 1. The IP address of Router 1 is 192.168.1.1, and it is in the same LAN as AP1. There is no AC in the LAN, and the ICMP message is forwarded to the next Router 2. When the ICMP message reaches Router 2, the ttl is reduced to 0, and the ICMP message is discarded. At the same time, Router 2 sends a timeout message corresponding to the ICMP message to AP1. AP1 can parse the timeout message and obtain the IP address of Router 2, 192.168.2.1, and then obtain the network segment to which 192.168.2.1 belongs, which is 192.168.2.*.
[0143] AP1 can traverse all IP addresses in the 192.168.2.* network segment, that is, 192.168.2.1 to 192.168.2.254, and send CAPWAP discovery messages to the devices corresponding to each IP address. Since Router 2 and AC are not in the same LAN, that is, they do not belong to the same network segment, AP1 cannot receive the response message of the CAPWAP discovery message. In this way, after AP1 has completed the detection of all IP addresses in the 192.168.2.* network segment, AP1 can continue to obtain the next network segment.
[0144] At this time, the survival time can be increased by 1, that is, ttl is 3. AP1 sends another ICMP message with a destination port of 46666 and a destination IP address of the IP address of the well-known website A, and the survival time ttl carried by the ICMP message is 3. Then, when the ICMP message reaches Router 3, the ttl is reduced to 0, and the ICMP message will be discarded. At the same time, Router 3 will send a timeout message corresponding to the ICMP message to AP1. AP1 can parse the timeout message and obtain the IP address of Router 3, 192.168.3.1, and then obtain the network segment to which 192.168.3.1 belongs, which is 192.168.3.*.
[0145] AP1 can traverse all IP addresses in the 192.168.3.* network segment, i.e., 192.168.3.1 to 192.168.3.254, and send CAPWAP discovery messages to the devices corresponding to each IP address. Since Router 3 and AC are in the same LAN, i.e., belong to the same network segment, AP1 can receive the response message of the CAPWAP discovery message sent by AC. AP1 parses the response message and obtains the IP address of AC as 192.168.3.10. Then, based on the IP address of AC, AP1 can send a connection request message to AC to establish a connection with AC and achieve communication.
[0146] It can be seen that in the scheme provided in the embodiment of the present application, it is applied to the first device, and the first device can send a first discovery message to a preset public network device, and the first discovery message carries a survival time, so that when the survival time expires, the second device that receives the first discovery message sends a timeout message to the first device, obtains the target network segment to which the source address of the timeout message belongs, and sends a second discovery message to the devices corresponding to multiple addresses in the target network segment. The destination port of the second discovery message is the port of the third device that provides communication services. If a discovery response message corresponding to the second discovery message is received, the source address of the discovery response message is used as the address of the third device. In theory, relative to the public network device, the third device that provides a server for the first device is closer to the first device. The first device sends a first discovery message carrying a survival time to the preset public network device. In this way, when the first discovery message does not reach the preset public network device, the survival time carried by the first discovery message expires, then the second device that sends the timeout message to the first device, its address (source address of the timeout message) belongs to the network segment is likely to be the network segment to which the address of the third device belongs. Therefore, the first device can detect the third device in the network segment to which the address of the second device belongs, and obtain the address of the third device. This enables the initiator to know the address of the receiver when the initiator and the receiver are in different local area networks, thereby realizing communication between the initiator and the receiver.
[0147] Corresponding to the above-mentioned service detection method, the embodiment of the present application further provides a service detection device. The following is an introduction to the service detection device provided by the embodiment of the present application.
[0148] like Figure 7 As shown, a service detection device is applied to a first device, and the device includes:
[0149] A first sending module 710 is used to send a first discovery message to a preset public network device, where the first discovery message carries a lifetime, so that a second device that receives the first discovery message sends a timeout message to the first device when the lifetime times out;
[0150] A target network segment acquisition module 720 is used to acquire the target network segment to which the source address of the timeout message belongs;
[0151] A second sending module 730 is used to send a corresponding device second discovery message to multiple addresses in the target network segment, where the destination port of the second discovery message is a port of a third device providing communication services;
[0152] The first determining module 740 is configured to use, if a discovery response message corresponding to the second discovery message is received, a source address of the discovery response message as the address of the third device.
[0153] It can be seen that in the scheme provided in the embodiment of the present application, it is applied to the first device, and the first device can send a first discovery message to a preset public network device, and the first discovery message carries a survival time, so that when the survival time expires, the second device that receives the first discovery message sends a timeout message to the first device, obtains the target network segment to which the source address of the timeout message belongs, and sends a second discovery message to the devices corresponding to multiple addresses in the target network segment. The destination port of the second discovery message is the port of the third device that provides communication services. If a discovery response message corresponding to the second discovery message is received, the source address of the discovery response message is used as the address of the third device. In theory, relative to the public network device, the third device that provides a server for the first device is closer to the first device. The first device sends a first discovery message carrying a survival time to the preset public network device. In this way, when the first discovery message does not reach the preset public network device, the survival time carried by the first discovery message expires, then the second device that sends the timeout message to the first device, its address (source address of the timeout message) belongs to the network segment is likely to be the network segment to which the address of the third device belongs. Therefore, the first device can detect the third device in the network segment to which the address of the second device belongs, and obtain the address of the third device. This enables the initiator to know the address of the receiver when the initiator and the receiver are in different local area networks, thereby realizing communication between the initiator and the receiver.
[0154] As an implementation of the embodiment of the present application, the above device may further include:
[0155] The first return module is used to increase the survival time by a preset time length if the discovery response message corresponding to the second discovery message is not received, and return to execute the step of sending the first discovery message to the preset public network device.
[0156] As an implementation of the embodiment of the present application, the above device may further include:
[0157] A first judgment module, used for judging whether the number of detections reaches a preset number of times before returning to execute the step of sending the first discovery message to the preset public network device, where the number of detections is the number of times the first device sends the first discovery message;
[0158] The second returning module is used to return to the step of sending the first discovery message to the preset public network device if no.
[0159] As an implementation of the embodiment of the present application, the above device may further include:
[0160] A second judgment module is used to judge whether the source address of the timeout message is a private address before the step of obtaining the target network segment to which the source address of the timeout message belongs;
[0161] The first execution module is used to execute the step of obtaining the target network segment to which the source address of the timeout message belongs if yes.
[0162] As an implementation of the embodiment of the present application, the above device may further include:
[0163] A detection message broadcasting module, used for broadcasting a detection message in the local area network to which the first device belongs, wherein the destination port of the detection message is a port of the third device;
[0164] A second determining module is configured to use, if a probe response message corresponding to the probe message fed back by the third device is received, a source address of the probe response message as the address of the third device;
[0165] The second execution module is used to execute the step of sending the first discovery message to the preset public network device if the detection response message corresponding to the detection message fed back by the third device is not received.
[0166] As an implementation of the embodiment of the present application, the above device may further include:
[0167] The third sending module is used to send a connection request message to the third device according to the address of the third device after obtaining the address of the third device, so that the third device establishes a connection with the first device, and the destination port of the connection request message is the port of the third device.
[0168] As an implementation manner of an embodiment of the present application, the above-mentioned first discovery message is a message of a connectionless protocol, and the destination port of the above-mentioned first discovery message is an unoccupied port.
[0169] The present application also provides an electronic device, such as Figure 8 As shown, including:
[0170] Memory 801, used for storing computer programs;
[0171] The processor 802 is used to implement the service detection method described in any of the above embodiments when executing the program stored in the memory 801.
[0172] Furthermore, the electronic device may further include a communication bus and / or a communication interface, and the processor 802, the communication interface, and the memory 801 communicate with each other via the communication bus.
[0173] It can be seen that in the scheme provided in the embodiment of the present application, it is applied to the first device, and the first device can send a first discovery message to a preset public network device, and the first discovery message carries a survival time, so that when the survival time expires, the second device that receives the first discovery message sends a timeout message to the first device, obtains the target network segment to which the source address of the timeout message belongs, and sends a second discovery message to the devices corresponding to multiple addresses in the target network segment. The destination port of the second discovery message is the port of the third device that provides communication services. If a discovery response message corresponding to the second discovery message is received, the source address of the discovery response message is used as the address of the third device. In theory, relative to the public network device, the third device that provides a server for the first device is closer to the first device. The first device sends a first discovery message carrying a survival time to the preset public network device. In this way, when the first discovery message does not reach the preset public network device, the survival time carried by the first discovery message expires, then the second device that sends the timeout message to the first device, its address (source address of the timeout message) belongs to the network segment is likely to be the network segment to which the address of the third device belongs. Therefore, the first device can detect the third device in the network segment to which the address of the second device belongs, and obtain the address of the third device. This enables the initiator to know the address of the receiver when the initiator and the receiver are in different local area networks, thereby realizing communication between the initiator and the receiver.
[0174] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0175] The communication interface is used for communication between the above electronic device and other devices.
[0176] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0177] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0178] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above service detection methods are implemented.
[0179] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any service detection method in the above embodiments.
[0180] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a solid-state hard disk (SSD), etc.
[0181] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0182] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, computer-readable storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0183] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. A service detection method, characterized in that: Applied to a first device, the method includes: Sending a first discovery message to a preset public network device, wherein the first discovery message carries a lifetime, so that a second device that receives the first discovery message sends a timeout message to the first device when the lifetime times out; Obtain the target network segment to which the source address of the timeout message belongs; Sending a second discovery message to devices corresponding to multiple addresses in the target network segment, where the destination port of the second discovery message is a port of a third device providing communication services; If a discovery response message corresponding to the second discovery message is received, the source address of the discovery response message is used as the address of the third device.
2. The method according to claim 1, characterized in that The method further comprises: If the discovery response message corresponding to the second discovery message is not received, the lifetime is increased by a preset time length, and the process returns to the step of sending the first discovery message to the preset public network device.
3. The method according to claim 2, characterized in that Before returning to execute the step of sending the first discovery message to the preset public network device, the method further includes: Determine whether the number of detections reaches a preset number, where the number of detections is the number of times the first device sends the first discovery message; If not, return to execute the step of sending the first discovery message to the preset public network device.
4. The method according to claim 1, characterized in that: Before the step of obtaining the target network segment to which the source address of the timeout message belongs, the method further includes: Determine whether the source address of the timeout message is a private address; If so, execute the step of obtaining the target network segment to which the source address of the timeout message belongs.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Broadcasting a detection message in the local area network to which the first device belongs, where the destination port of the detection message is a port of the third device; If a probe response message corresponding to the probe message fed back by the third device is received, the source address of the probe response message is used as the address of the third device; If the detection response message corresponding to the detection message fed back by the third device is not received, the step of sending the first discovery message to the preset public network device is executed.
6. The method according to any one of claims 1 to 4, characterized in that: After obtaining the address of the third device, the method further includes: According to the address of the third device, a connection request message is sent to the third device, so that the third device establishes a connection with the first device, and the destination port of the connection request message is a port of the third device.
7. The method according to any one of claims 1 to 4, characterized in that: The first discovery message is a message of a connectionless protocol, and a destination port of the first discovery message is an unoccupied port.
8. A service detection device, characterized in that: Applied to a first device, the apparatus comprises: A first sending module, configured to send a first discovery message to a preset public network device, wherein the first discovery message carries a lifetime, so that a second device that receives the first discovery message sends a timeout message to the first device when the lifetime times out; A target network segment acquisition module, used to acquire the target network segment to which the source address of the timeout message belongs; A second sending module, used to send a second discovery message to devices corresponding to multiple addresses in the target network segment, wherein the destination port of the second discovery message is a port of a third device providing communication services; The first determining module is configured to use, if a discovery response message corresponding to the second discovery message is received, a source address of the discovery response message as the address of the third device.
9. The device according to claim 8, characterized in that The device also includes: A first returning module, configured to increase the survival time by a preset time length and return to executing the step of sending the first discovery message to the preset public network device if a discovery response message corresponding to the second discovery message is not received; The device also includes: A first judgment module, used for judging whether the number of detections reaches a preset number of times before returning to execute the step of sending the first discovery message to the preset public network device, where the number of detections is the number of times the first device sends the first discovery message; A second returning module, configured to return to the step of sending the first discovery message to the preset public network device if no; The device also includes: A second judgment module is used to judge whether the source address of the timeout message is a private address before the step of obtaining the target network segment to which the source address of the timeout message belongs; A first execution module, configured to execute the step of obtaining the target network segment to which the source address of the timeout message belongs if yes; The device also includes: A detection message broadcasting module, used for broadcasting a detection message in the local area network to which the first device belongs, wherein the destination port of the detection message is a port of the third device; A second determining module is configured to use, if a probe response message corresponding to the probe message fed back by the third device is received, a source address of the probe response message as the address of the third device; A second execution module, configured to execute the step of sending a first discovery message to a preset public network device if a detection response message corresponding to the detection message fed back by the third device is not received; The device also includes: A third sending module is used to send a connection request message to the third device according to the address of the third device after obtaining the address of the third device, so that the third device establishes a connection with the first device, and the destination port of the connection request message is the port of the third device; The first discovery message is a message of a connectionless protocol, and a destination port of the first discovery message is an unoccupied port.
10. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-7 when executing a program stored in a memory.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.