Local area network topology drawing method and system based on set algorithm
Through a method based on the ensemble algorithm, the SNMP tool is used to obtain device information and connection relationships, and the physical connection relationships of LAN devices are directly inferred, which solves the problems of complexity and low efficiency of topology generation in the existing technology, and achieves low cost and low time consumption LAN topology drawing.
Patent Information
- Application Number
- CN202411311577.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-19
- Publication Date
- 2024-12-27
AI Technical Summary
The prior art requires analyzing routing tables in the generation of local area network topology, which leads to complex operations, time-consuming and increased costs. The implementation of the Tarjan algorithm is complex and relies on recursive or iterative processes, limiting the topology drawing efficiency.
Using a method based on ensemble algorithm, the network device information and connection relationship are obtained through SNMP tools, and the ensemble algorithm is used to directly infer the physical connection relationship between devices, draw the LAN topology, avoid analyzing the routing table, and realize low-cost and low-time-consuming topology drawing. .
The physical topological relationship between local area network devices is directly derived through the ensemble algorithm, which reduces the computational complexity and cost, improves the topological drawing efficiency, and realizes low-cost and low-time-consuming LAN topological drawing.
Smart Images

Figure CN119211032A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of local area network information processing, and more specifically, to a local area network topology drawing method and system based on a set algorithm. Background Art
[0002] In the existing LAN topology generation technology, it can only be judged whether the interfaces of two devices display each other's MAC address. If so, it is inferred that the two devices may be directly connected, and then the routing table is further analyzed to roughly infer the routing path and hierarchical relationship between the devices, and then the LAN topology relationship is generated;
[0003] The existing technology needs to further analyze the routing table to infer the network layer through the routing relationship, but it is redundant to directly derive the physical connection relationship between devices in the local area network, which requires more time and cost during operation; and the existing technology usually needs to rely on recursion or iterative processes to traverse the graph structure, so in practical applications, it is also necessary to consider the limitation of recursive depth or number of iterations, which increases the computing cost and reduces the efficiency of topology drawing.
[0004] The existing technology can use the Tarjan algorithm to realize the topology generation of network switches, but the implementation of the Tarjan algorithm is relatively complicated, involving the maintenance of multiple arrays and stacks, as well as complex logical judgments in the recursive or iterative process, which results in more time and cost in the operation process; and the algorithm relies on the recursive or iterative process to traverse the graph structure, so in practical applications, it is also necessary to consider the limitation of the recursive depth or the number of iterations. Summary of the invention
[0005] In order to solve the deficiencies in the prior art, the present invention provides a local area network topology drawing method based on a set algorithm, which can solve the technical problem of complex calculations in obtaining topological relationships in the prior art.
[0006] The present invention adopts the following technical solution.
[0007] A local area network topology drawing method based on a set algorithm comprises the following steps:
[0008] Step 1: Obtain network device information in the local area network, compare the network device information with the user ledger to obtain a list of network device assets;
[0009] Step 2, obtaining the connection information of the devices in the local area network and obtaining the connection relationship between the devices;
[0010] Step 3, according to the network device asset list and the device connection relationship, obtain the network devices whose connection relationship is directly connected through the set algorithm;
[0011] Step 4: Draw a local area network topology based on the connection relationship between the devices and the directly connected network devices.
[0012] Preferably, in step 1, the SNMP management information base tree on the LAN device is traversed through the SNMP tool to obtain network device information, including device name, IP address, MAC address, and the obtained network device information is compared with the user ledger to complete the missing content and obtain a network device asset list.
[0013] Preferably, in step 2, using SNMP commands to obtain connection information of devices in the local area network specifically includes:
[0014] By querying the interface table and routing table information of the device and analyzing them, the connection relationship between the devices is obtained, including the device information connected to the port of each network device, and the devices include network devices and non-network devices.
[0015] Preferably, querying the interface table and routing table information of the device and analyzing them specifically includes:
[0016] The SNMP information of the network device is obtained through the SNMP protocol, a double-ended queue containing key-value pairs is obtained based on the SNMP information, and the device information connected to each network device port is obtained by traversing the double-ended queue.
[0017] Preferably, each key-value pair in the double-ended queue comprises an SNMP identifier and its corresponding value, wherein the SNMP identifier represents a network device port, and the corresponding value represents a MAC address corresponding to the network device port.
[0018] Preferably, in step 3, obtaining the connection relationship of the network devices by a set algorithm specifically includes:
[0019] Step 3-1, constructing a linked list based on the network device asset list obtained in step 1 and the connection relationship between the devices obtained in step 2, wherein the linked list includes a set of network devices connected to each network device port;
[0020] Step 3-2, traverse the constructed linked list through a double loop to find another port set of all network devices whose port sets in the linked list have no intersection with the port and whose union is directly connected to the two ports. The directly connected network devices are obtained through the connection relationship of the network device ports.
[0021] Preferably, in step 4, a local area network topology diagram is constructed together according to the connection relationship between the non-network device and the network device obtained in step 2 and the directly connected network devices obtained in step 3.
[0022] The present invention also proposes a local area network topology drawing device based on a set algorithm using the local area network topology drawing method based on a set algorithm, comprising: a device information acquisition module, a connection relationship acquisition module, a set algorithm processing module and a topology drawing module;
[0023] The device information acquisition module is used to obtain network device information in the local area network, and compare the network device information with the user ledger to obtain a list of network device assets.
[0024] The connection relationship acquisition module is used to obtain the connection information of devices in the local area network and obtain the connection relationship between devices, including the connection relationship between network devices and non-network devices;
[0025] The collection algorithm processing module can obtain network devices with directly connected connection relationships through a collection algorithm according to the network device asset list and device connection relationships;
[0026] The topology drawing module draws the LAN topology based on the connection relationship between network devices and non-network devices, as well as directly connected network devices.
[0027] The present invention also provides a terminal, comprising a processor and a storage medium;
[0028] The storage medium is used to store instructions;
[0029] The processor is used to operate according to the instructions to execute the steps of the local area network topology drawing method based on the set algorithm.
[0030] The present invention also proposes a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the local area network topology drawing method based on the set algorithm are implemented.
[0031] The beneficial effect of the present invention is that compared with the prior art, the LAN topology drawing method proposed in the present invention can obtain the MAC address binding relationship between the port and the network device through the SNMP tool without analyzing the routing table. Based on the set algorithm proposed in the present invention, the connection relationship between the LAN devices can be inferred only through the relationship between the port and the MAC address, thereby directly obtaining the physical topology between the various devices in the LAN. The set algorithm can achieve low-cost and low-time LAN topology drawing. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 It is a flow chart of a local area network topology drawing method based on a set algorithm in the present invention;
[0033] Figure 2 It is a schematic diagram of the connection topology of switches in the local area network of the present invention;
[0034] Figure 3It is a schematic diagram of a disjoint set generated by the set algorithm of the present invention;
[0035] Figure 4 It is a schematic diagram of an intersection set generated by the set algorithm of the present invention;
[0036] Figure 5 It is a structural diagram of the local area network topology drawing system based on the set algorithm in the present invention. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical scheme and advantages of the present invention clearer, the technical scheme of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. The embodiments described in this application are only part of the embodiments of the present invention, not all of them. Based on the spirit of the present invention, other embodiments obtained by ordinary technicians in this field without creative work are all within the scope of protection of the present invention.
[0038] like Figure 1 As shown, the present invention proposes a local area network topology drawing method based on a set algorithm, and the method specifically includes the following steps:
[0039] Step 1: Use SNMP tools to scan devices in the LAN to obtain device information, and compare the device information with the user ledger to obtain a list of network device assets;
[0040] First, use SNMP tools (such as snmpwalk) to scan the devices in the LAN. The SNMPwalk command can traverse the SNMP Management Information Base (MIB) tree on the device to obtain various information about the device, including the device name, IP address, and MAC address. The device information obtained by the scan is compared with the user ledger to complete the missing content and obtain an accurate list of network device assets.
[0041] Step 2: Collect the connection information of the devices through SNMP commands to obtain the connection relationship between the devices;
[0042] Use SNMP commands to collect device connection information:
[0043] By querying and analyzing the interface table and routing table information of the device, the connection relationship between the devices is obtained, including the device information connected to the port of each network device, and the devices include network devices and non-network devices.
[0044] Specifically, querying the interface table and routing table information of the device and analyzing them includes the following steps:
[0045] Obtain information about network devices through the SNMP protocol, including ports and corresponding MAC addresses.
[0046] After successfully obtaining the snmp information, a double-ended queue deque containing key-value pairs is obtained, where each key-value pair represents a SNMPOID (Object Identifier) and its corresponding value. The key (i.first) represents the identifier (port name), and the value (i.second) is the corresponding actual data (MAC address).
[0047] Then, it iterates over the deque, and for each key-value pair, it does the following:
[0048] 1. Convert the MAC address in (i.second) to an actual readable MAC address;
[0049] 2. Store the key-value pair (MAC address and port name) in the database.
[0050] The connection relationship obtained in step 2 only includes which network devices are connected to the ports of each network device, but cannot determine whether each network device is directly or indirectly connected to another network device.
[0051] As an implementation method, Figure 2 As shown, Figure 2 The tree structure on the left is the connection topology between the real switches in the LAN, and the series of sets on the right are the connection information of the devices collected by the present invention through SNMP commands. Figure 2 The switches SW1, SW2, SW3, SW4, SW5, and SW6 are network devices. The network ports of the switches represent the ports of the network devices. For example, the network port 1 of the SW1 switch can be obtained that there are four switches connected to it, namely SW2, SW3, SW4, and SW6, but it cannot be determined that SW2 is directly connected to SW1.
[0052] Step 3, based on the network device asset list obtained in step 1 and the device connection relationship obtained in step 2, a collection algorithm is used to obtain whether the connection relationship of the network device is directly connected or indirectly connected;
[0053] The LAN topology relationship is usually obtained by inferring the configuration information of each device. In the prior art, the LAN information obtained using the SNMP tool is usually used to directly construct the topology. This situation results in the topology information obtained being unable to directly reflect the specific connection relationship of the network devices, thereby affecting the accuracy and speed of the topology construction. The present invention recognizes that in order to achieve low-cost and low-time LAN topology drawing, the network device information and device connection relationship obtained based on SNMP should be further processed to obtain a more accurate network device connection relationship. In order to achieve this technical effect, the present invention creatively proposes a set algorithm, which is suitable for processing the network device information and device connection relationship obtained based on the SNMP tool and further obtaining the accurate connection relationship of the network devices.
[0054] Constructing a topology map: Based on the collected network device information and device connection relationships, a network topology map is constructed using a collection algorithm. The collection algorithm can process nodes (network devices) and edges (connection relationships) in the network to generate a graph representing the network structure, such as Figure 2 shown.
[0055] (1) The connection relationship between the network devices obtained through steps 1 and 2 is stored in a database table, the connection relationship on each port of the network device is obtained by screening in the database, and the obtained connection relationship is stored in a linked list, the linked list includes the same number of sets as the number of ports, and each port set includes the MAC address of the network device connected to the port;
[0056] (2) Use a double loop to traverse the linked list to ensure that each port set can find another port set that has no intersection with itself and whose union is the total set of all network devices, indicating that the two ports are directly connected.
[0057] As an implementation method, Figure 2 As shown, the switch set that can be obtained by port 1 of switch SW1 includes SW2, SW3, SW4, and SW6, while the set that can be obtained by port 3 of switch SW2 includes SW1 and SW5. It can be seen that there is no intersection between the two sets and the union of the two sets is equal to the total set of all switches, as shown in Figure 3 In this case, it can be concluded that port 1 of SW1 and port 3 of SW2 are directly connected.
[0058] In addition, if there is an intersection between the two sets such as Figure 4 As shown, in this case, it can be determined that port 1 of SW1 is not directly connected to port 5 of SW3, but is indirectly connected.
[0059] Through the above principles, directly connected network devices can be found one by one, thereby obtaining the topological relationship of the network devices.
[0060] Step 4: construct a local area network topology map based on the connection relationship of the network devices, and visualize the constructed topology map.
[0061] Specifically, the devices in the local area network include network devices and non-network devices. The non-network devices include hosts, monitoring devices, servers and other devices. The connection relationship between the non-network devices and the network devices obtained in step 2 is combined with the connection relationship obtained in step 3 for directly connected network devices to jointly construct a local area network topology diagram.
[0062] Visualize the constructed topology map: read the data in the database for display through a graphical interface, web page or other visualization tools. Users can use these display tools to intuitively understand the distribution and connection status of network devices.
[0063] like Figure 5 As shown, the present invention also proposes a local area network topology drawing device based on a set algorithm, which can be used to implement the local area network topology drawing method based on a set algorithm. The system includes: a device information acquisition module, a connection relationship acquisition module, a set algorithm processing module and a topology drawing module;
[0064] The device information acquisition module is used to obtain network device information in the local area network, and compare the network device information with the user ledger to obtain a list of network device assets.
[0065] The connection relationship acquisition module is used to obtain the connection information of devices in the local area network and obtain the connection relationship between the devices;
[0066] The collection algorithm processing module can obtain the connection relationship of network devices as direct or indirect connection through the collection algorithm according to the network device asset list and device connection relationship.
[0067] The topology drawing module constructs the LAN topology based on the connection relationship of network devices.
[0068] The beneficial effect of the present invention is that, compared with the prior art, the set algorithm proposed in the present invention can infer the connection relationship between LAN devices only through the relationship between ports and MAC addresses, thereby directly obtaining the physical topology between various devices in the LAN. The set algorithm can realize low-cost and low-time LAN topology drawing.
[0069] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0070] Computer readable storage medium can be a tangible device that can keep and store the instructions used by the instruction execution device. Computer readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: portable computer disk, hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD), memory stick, floppy disk, mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. Computer readable storage medium used here is not interpreted as instantaneous signal itself, such as radio waves or other free propagating electromagnetic waves, electromagnetic waves propagated by waveguides or other transmission media (for example, light pulses by optical fiber cables), or electrical signals transmitted by wires.
[0071] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0072] The computer program instructions for performing the disclosed operation may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the disclosed invention.
[0073] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents, and any modifications or equivalent replacements that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A local area network topology drawing method based on a set algorithm, characterized in that: The steps include: Step 1: Obtain network device information in the local area network, compare the network device information with the user ledger to obtain a list of network device assets; Step 2, obtaining the connection information of the devices in the local area network and obtaining the connection relationship between the devices; Step 3, according to the network device asset list and the device connection relationship, obtain the network devices whose connection relationship is directly connected through the set algorithm; Step 4: Draw a local area network topology based on the connection relationship between the devices and the directly connected network devices.
2. The local area network topology drawing method based on set algorithm according to claim 1 is characterized in that: In step 1, the SNMP management information base tree on the LAN device is traversed through the SNMP tool to obtain network device information, including device name, IP address, and MAC address. The obtained network device information is compared with the user ledger, and the missing content is completed to obtain a network device asset list.
3. The local area network topology drawing method based on set algorithm according to claim 1 is characterized in that: In step 2, the SNMP command is used to obtain the connection information of the device in the local area network, specifically including: By querying the interface table and routing table information of the device and analyzing them, the connection relationship between the devices is obtained, including the device information connected to the port of each network device, and the devices include network devices and non-network devices.
4. The local area network topology drawing method based on set algorithm according to claim 3 is characterized in that: By querying the device's interface table and routing table information and analyzing it, the following are performed: The SNMP information of the network device is obtained through the SNMP protocol, a double-ended queue containing key-value pairs is obtained based on the SNMP information, and the device information connected to each network device port is obtained by traversing the double-ended queue.
5. The local area network topology drawing method based on set algorithm according to claim 4 is characterized in that: Each key-value pair in the double-ended queue includes an SNMP identifier and its corresponding value, wherein the SNMP identifier represents a network device port, and the corresponding value represents a MAC address corresponding to the network device port.
6. The local area network topology drawing method based on set algorithm according to claim 1, characterized in that: In step 3, the connection relationship of the network devices is obtained by a set algorithm, which specifically includes: Step 3-1, constructing a linked list based on the network device asset list obtained in step 1 and the connection relationship between the devices obtained in step 2, wherein the linked list includes a set of network devices connected to each network device port; Step 3-2, traverse the constructed linked list through a double loop, find each port set in the linked list has no intersection with the port and the union is another port set of all network devices, indicating that the two ports are directly connected, and the directly connected network devices are obtained through the connection relationship of the network device ports.
7. The local area network topology drawing method based on set algorithm according to claim 1, characterized in that: In step 4, a local area network topology diagram is constructed based on the connection relationship between the non-network device and the network device obtained in step 2 and the directly connected network devices obtained in step 3.
8. A local area network topology drawing device based on a set algorithm using the local area network topology drawing method based on a set algorithm as claimed in any one of claims 1 to 7, characterized in that: include: Device information acquisition module, connection relationship acquisition module, set algorithm processing module and topology drawing module; The device information acquisition module is used to obtain network device information in the local area network, and compare the network device information with the user ledger to obtain a list of network device assets. The connection relationship acquisition module is used to obtain the connection information of devices in the local area network and obtain the connection relationship between devices, including the connection relationship between network devices and non-network devices; The collection algorithm processing module can obtain network devices with directly connected connection relationships through a collection algorithm according to the network device asset list and device connection relationships; The topology drawing module draws the LAN topology based on the connection relationship between network devices and non-network devices, as well as directly connected network devices.
9. A terminal comprising a processor and a storage medium; characterized in that: The storage medium is used to store instructions; The processor is configured to operate according to the instructions to execute the steps of the method according to any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
