A method for gateway device interface configuration matching, an electronic device, and a storage medium
By dynamically binding interface types in the gateway device, the problem of manually distinguishing between WAN and LAN interfaces in traditional gateway devices is solved, achieving automatic adaptation and improving configuration accuracy and development efficiency.
Patent Information
- Application Number
- CN202411540204.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-31
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2044-10-31
AI Technical Summary
Traditional gateway device interface configuration methods require manually distinguishing between WAN and LAN ports, resulting in a heavy workload for network developers and a high risk of errors. Existing technologies cannot achieve automatic adaptation.
By adding all interfaces of the switching module to the first bridge in the gateway device, configuring a virtual LAN, and dynamically binding the interface type according to the interface ID list and connection status, automatic adaptation is achieved.
It enables automatic network interface adaptation, reduces manual operations, improves the efficiency of network developers, and ensures the accuracy of interface configuration.
Smart Images

Figure CN119420714B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of network communication, in particular to a gateway device interface configuration matching method, an electronic device and a storage medium. BACKGROUND
[0002] With the popularity of the network, users access the gateway through the wifi router and other devices. However, the traditional gateway communication products usually distinguish WAN port and LAN port through fixed physical network port, wherein the WAN port is used to connect the external network, and the LAN port is used to connect the local area network. When the number of network cables is large, the user cannot distinguish whether the network port is WAN port or LAN port, and the network cable cannot be distinguished, which leads to network cable connection error, so that the network device cannot access the Internet, and the terminal cannot access the gateway device for configuration operation. Therefore, it is a hot research direction to set up a system so that the user does not need to distinguish WAN port and LAN port, and the gateway device can automatically adapt after the network cable is connected.
[0003] The gateway device interface configuration matching method in the prior art is to establish a network bridge on the WAN port and the LAN port respectively, bind the network port to the network bridge corresponding to the WAN port and the LAN port respectively, or directly configure different network ports as WAN ports. These methods change the three-layer network port name, which leads to the modification of the network port name corresponding to the application layer related application, increases the workload of network developers, and reduces the efficiency. SUMMARY
[0004] In view of the above technical problems, the technical scheme adopted by the present application is as follows: a gateway device interface configuration matching method, comprising the following steps:
[0005] S100, all interfaces of a switching module in a gateway device are added to a network bridge established on a first network port, and a first virtual local area network is configured, wherein the gateway device comprises a main controller and a switching module, the main controller sets a first network port and a second network port, the first network port is configured as a LAN port, and the second network port is configured as a WAN port.
[0006] S200, according to the interfaces in the switching module, a candidate interface ID list is confirmed, wherein the candidate interface ID list comprises a plurality of candidate interface IDs, the candidate interface ID is the name corresponding to the candidate interface, and the candidate interface is the connected interface in the switching module.
[0007] S300, according to the candidate interface ID list, an initial network interface type list corresponding to the candidate interface ID list is obtained, wherein the initial network interface type list comprises a plurality of initial network interface types, each candidate interface ID corresponds to an initial network interface type, and in S300, the following steps are further included:
[0008] S301, remove the candidate interface corresponding to the candidate interface ID from the bridge of the first network port, and configure the candidate interface corresponding to the candidate interface ID with a second virtual local area network and bind it with the second network port.
[0009] S302, obtain the target network access mode corresponding to the second network port from the network configuration file, wherein the target network access mode is the mode of the second network port accessing the Internet in the gateway device.
[0010] S303, according to the target network access mode, obtain the target identifier corresponding to the candidate interface ID.
[0011] S304, when the target identifier is '1', save the candidate interface ID in the target variable to obtain the initial network interface type corresponding to the candidate interface ID as a WAN port, wherein the target variable is a storage space for storing data.
[0012] S305, when the target identifier is '0', configure the candidate interface corresponding to the candidate interface ID with a first virtual local area network and add the candidate interface ID to the bridge of the first network port to obtain the initial network interface type corresponding to the candidate interface ID as a LAN port.
[0013] S400, obtain the target connection state of all interfaces of the switching module in the gateway device, wherein the target connection state is the connection state of the interfaces in the switching module in the gateway device obtained at intervals of a preset time length.
[0014] S500, according to the target connection state, match the interface configuration of the switching module in the gateway device, wherein the interface configuration of the switching module in the gateway device is a LAN port or a WAN port.
[0015] The application protects a computer device, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the above-mentioned gateway device interface configuration matching method when executing the computer program.
[0016] The application protects a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the above-mentioned gateway device interface configuration matching method.
[0017] The application has at least the following beneficial effects: a gateway device interface configuration matching method, comprising the following steps: adding all interfaces of a switching module in the gateway device to a bridge established on a first network port, and configuring a first virtual local area network; confirming a candidate interface ID list according to the interfaces in the switching module; obtaining an initial network interface type list corresponding to the candidate interface ID list according to the candidate interface ID list, wherein the candidate interface corresponding to the candidate interface ID is removed from the bridge of the first network port, and the candidate interface corresponding to the candidate interface ID is configured with a second virtual local area network and bound with a second network port; obtaining a target access mode corresponding to the second network port from a network configuration file; obtaining a target identifier corresponding to the candidate interface ID according to the target access mode; confirming an initial network interface type based on the target identifier; obtaining a target connection state corresponding to all interfaces of the switching module in the gateway device; and matching the interface configuration of the switching module in the gateway device according to the target connection state. The application keeps the network port name on the main controller unchanged, dynamically binds the network port in the main controller with each physical interface of the switching module according to the connection condition, matches the interface configuration by using different processing modes based on the different connection states of each physical interface of the switching module, realizes the network port automatic adaptation function, makes the interface configuration matching more accurate, and makes the main controller use the fixed interface uniformly without additional processing, so that the operation is convenient and the efficiency of the network developer is improved. BRIEF DESCRIPTION OF DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.
[0019] Figure 1 A flowchart of a gateway device interface configuration matching method provided by the embodiment of the present application. DETAILED DESCRIPTION
[0020] The technical solutions in the embodiments of the present application will be described clearly and completely in the following with reference to the drawings of the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, not all the embodiments. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of the present application.
[0021] EMBODIMENT
[0022] The embodiment provides a gateway device interface configuration matching method, and the method comprises the following steps, as shown in the following Figure 1 .
[0023] S100, adding all interfaces of a switching module in a gateway device to a bridge established on a first network port, and configuring a first virtual local area network, wherein the gateway device comprises a main controller and the switching module, the main controller sets a first network port and a second network port, the first network port is configured as a LAN port, and the second network port is configured as a WAN port.
[0024] S200, confirming a candidate interface ID list according to interfaces in the switching module, wherein the candidate interface ID list comprises a plurality of candidate interface IDs, each candidate interface ID is a name corresponding to a candidate interface, and the candidate interface is a connected interface in the switching module.
[0025] S300, obtaining an initial network interface type list corresponding to the candidate interface ID list according to the candidate interface ID list, wherein the initial network interface type list comprises a plurality of initial network interface types, and each candidate interface ID corresponds to an initial network interface type.
[0026] Specifically, S300 further comprises the following steps:
[0027] S301, removing a candidate interface corresponding to a candidate interface ID from the bridge of the first network port, and configuring the candidate interface corresponding to the candidate interface ID with a second virtual local area network and binding the candidate interface to the second network port.
[0028] S302, obtaining a target network access mode corresponding to the second network port from a network configuration file, wherein the target network access mode is a mode in which the second network port accesses the Internet in the gateway device.
[0029] S303, obtaining a target identifier corresponding to the candidate interface ID according to the target network access mode, wherein the target identifier is obtained through the following steps in S303:
[0030] S3031, when the target network access mode is configured as DHCP and a DHCP service exists in a connection section of the second network port, obtaining the target identifier as “1”, wherein the judgment that the DHCP service exists in the connection section of the second network port is performed by detecting through a udhcpc tool.
[0031] S3032, when the target network access mode is configured as DHCP and a DHCP service does not exist in the connection section of the second network port, obtaining the target identifier as “0”.
[0032] S3033, when the target network access mode is configured as PPPoE and a PPPoE service exists in the connection section of the second network port, obtaining the target identifier as “1”, wherein the judgment that the PPPoE service exists in the connection section of the second network port is performed by detecting through a pppoe-discovery tool.
[0033] S3034, when the target access mode is configured as PPPoE and the second network port connection end does not exist a PPPoE service, obtaining the target identification as "0".
[0034] S3035, when the target access mode is configured as static IP and the second network port gateway IP is pinged, obtaining the target identification as "1", wherein the judgment mode that the second network port gateway IP is pinged is that the ping tool is used to detect the second network port gateway IP address obtained from the network configuration file.
[0035] S3036, when the target access mode is configured as static IP and the second network port gateway IP is not pinged, obtaining the target identification as "0".
[0036] S304, when the target identification is "1", saving the candidate interface ID into the target variable to obtain the initial network interface type corresponding to the candidate interface ID as WAN port, wherein the target variable is a storage space for storing data.
[0037] S305, when the target identification is "0", configuring the first virtual local area network for the candidate interface corresponding to the candidate interface ID and adding the candidate interface ID to the bridge of the first network port to obtain the initial network interface type corresponding to the candidate interface ID as LAN port.
[0038] S400, obtaining the target connection state corresponding to all interfaces of the switching module in the gateway device, wherein the target connection state is the connection state of the interface in the switching module in the gateway device obtained at intervals of a preset time length.
[0039] Specifically, those skilled in the art know that the selection of the preset time length can be made according to actual needs, which falls within the protection scope of the present application, and will not be repeated here.
[0040] S500, matching the interface configuration of the switching module in the gateway device according to the target connection state, wherein the interface configuration of the switching module in the gateway device is LAN port or WAN port.
[0041] Specifically, S500 further includes the following steps:
[0042] S501, obtaining a first key interface ID list according to the target connection state, wherein the first key interface ID list includes a plurality of first key interface IDs, and the first key interface ID is the name corresponding to the first key interface.
[0043] Specifically, the first key interface is an interface whose target connection state is displayed as connected, which is obtained from all interfaces of the switching module except the candidate interface.
[0044] S502, a first processing mode is used to process the first key interface ID list, and an interface configuration corresponding to each first key interface ID is obtained to realize matching of the interface configuration of the switching module.
[0045] Specifically, in S502, the following steps are further included:
[0046] S1, when the target variable is not an empty set, the first key interface configuration is kept unchanged to determine that the first key interface configuration is a LAN port.
[0047] S2, when the target variable is an empty set, the first key interface corresponding to the first key interface ID is removed from the bridge of the first network port, and the first key interface configuration corresponding to the first key interface ID is bound to a second virtual local area network and the second network port.
[0048] S3, a target access mode corresponding to the second network port is obtained from a network configuration file, wherein the target access mode is a mode in which the second network port accesses the Internet in the gateway device.
[0049] S4, according to the target access mode, a key identifier corresponding to the first key interface ID is obtained, wherein in S4, the key identifier is obtained by the following steps:
[0050] S41, when the target access mode is configured as DHCP and the second network port connection segment has a DHCP service, the key identifier is obtained as “1”, wherein the judgment mode that the second network port connection segment has a DHCP service is to detect by using a udhcpc tool.
[0051] S42, when the target access mode is configured as DHCP and the second network port connection segment does not have a DHCP service, the key identifier is obtained as “0”.
[0052] S43, when the target access mode is configured as PPPoE and the second network port connection segment has a PPPoE service, the key identifier is obtained as “1”, wherein the judgment mode that the second network port connection segment has a PPPoE service is to detect by using a pppoe-discovery tool.
[0053] S44, when the target access mode is configured as PPPoE and the second network port connection segment does not have a PPPoE service, the key identifier is obtained as “0”.
[0054] S45, when the target access mode is configured as static IP and the second network port gateway IP is pinged, the key identifier is obtained as “1”, wherein the judgment mode that the second network port gateway IP is pinged is to detect the second network port gateway IP address obtained from the network configuration file by using a ping tool.
[0055] S46, when the target network access mode is configured as static IP and the second network port gateway IP is not pingable, obtaining a key identifier as "0".
[0056] S5, when the key identifier is "1", saving the first key interface ID into a target variable to obtain that the interface corresponding to the first key interface ID is configured as a WAN port, wherein the target variable is a storage space for storing data.
[0057] S6, when the key identifier is "0", configuring the first key interface corresponding to the first key interface ID with a first virtual local area network and adding the first key interface ID to the bridge of the first network port to obtain that the interface corresponding to the first key interface ID is configured as a LAN port.
[0058] S503, according to the target connection state, obtaining a second key interface ID list, wherein the second key interface ID list includes a plurality of second key interface IDs, and the second key interface ID is the name corresponding to the second key interface.
[0059] Specifically, the second key interface is an interface whose target connection state is displayed as disconnected in the plurality of candidate interfaces.
[0060] S504, processing the second key interface ID list by using a second processing mode to obtain the interface configuration corresponding to each second key interface ID to realize the matching of the interface configuration of the switching module.
[0061] Specifically, S504 further includes the following steps:
[0062] S5041, when the second key interface ID is consistent with the interface ID recorded in the target variable, configuring the second key interface corresponding to the second key interface ID with a first virtual local area network and adding the second key interface ID to the bridge of the first network port while emptying the target variable to obtain that the target network interface type corresponding to the second key interface ID is a LAN port.
[0063] S5042, when the second key interface ID is inconsistent with the interface ID recorded in the target variable, keeping the second key interface configuration unchanged to determine that the second key interface is configured as a LAN port.
[0064] As can be known from the above, the embodiment keeps the network port name on the main controller unchanged, dynamically binds the network port in the main controller and each physical interface of the switching module according to the connection state, matches the interface configuration by using different processing modes based on the different connection states of each physical interface of the switching module, realizes the network port automatic adaptation function, makes the interface configuration matching more accurate, and makes the main controller use the fixed interface uniformly without additional processing, so that the operation is convenient and the efficiency of the network developer is improved.
[0065] The embodiment provides a gateway device interface configuration matching method, which comprises the following steps: adding all interfaces of a switching module in a gateway device to a bridge established on a first network port, configuring a first virtual local area network, confirming a candidate interface ID list according to the interfaces in the switching module, obtaining an initial network interface type list corresponding to the candidate interface ID list according to the candidate interface ID list, wherein the candidate interface corresponding to the candidate interface ID is removed from the bridge of the first network port, and the candidate interface corresponding to the candidate interface ID is configured with a second virtual local area network and is bound with a second network port, obtaining a target network access mode corresponding to the second network port from a network configuration file, obtaining a target identifier corresponding to the candidate interface ID according to the target network access mode, confirming an initial network interface type based on the target identifier, obtaining a target connection state corresponding to all interfaces of the switching module in the gateway device, and matching the interface configuration of the switching module in the gateway device according to the target connection state.
[0066] The embodiment of the present application further provides a non-transitory computer readable storage medium, which can be arranged in an electronic device to save at least one instruction or at least one program related to a method in the method embodiment, and the at least one instruction or the at least one program is loaded and executed by the processor to realize the method provided by the above embodiment.
[0067] The embodiment of the present application further provides an electronic device, which comprises a processor and the aforementioned non-transitory computer readable storage medium.
[0068] Although some specific embodiments of the present application have been described in detail by examples, those skilled in the art should understand that the above examples are only for illustration, but not for limiting the scope of the present application. Those skilled in the art should also understand that various modifications can be made to the embodiments without departing from the scope and spirit of the present application. The scope of the present application is defined by the appended claims.
Claims
1. A method for matching gateway device interface configurations, characterized in that, The method comprises the following steps: S100, adding all interfaces of a switching module in a gateway device to a bridge established on a first network port, and configuring a first virtual local area network, wherein the gateway device comprises a main controller and the switching module, the main controller sets a first network port and a second network port, the first network port is configured as a LAN port, and the second network port is configured as a WAN port; S200, confirming a candidate interface ID list according to interfaces in the switching module, wherein the candidate interface ID list comprises a plurality of candidate interface IDs, the candidate interface ID is a name corresponding to a candidate interface, and the candidate interface is a connected interface in the switching module; S300, obtaining an initial network interface type list corresponding to the candidate interface ID list according to the candidate interface ID list, wherein the initial network interface type list comprises a plurality of initial network interface types, each candidate interface ID corresponds to an initial network interface type, and S300 further comprises the following steps: S301, removing a candidate interface corresponding to a candidate interface ID from the bridge of the first network port, and configuring the candidate interface corresponding to the candidate interface ID as a second virtual local area network and binding the candidate interface corresponding to the candidate interface ID to the second network port; S302, obtaining a target access mode corresponding to the second network port from a network configuration file, wherein the target access mode is a mode in which the second network port of the gateway device accesses the Internet; S303, obtaining a target identifier corresponding to the candidate interface ID according to the target access mode; S304, when the target identifier is "1", saving the candidate interface ID to a target variable to obtain that the initial network interface type corresponding to the candidate interface ID is a WAN port, wherein the target variable is a storage space for storing data; S305, when the target identifier is "0", configuring the candidate interface corresponding to the candidate interface ID as a first virtual local area network and adding the candidate interface ID to the bridge of the first network port to obtain that the initial network interface type corresponding to the candidate interface ID is a LAN port; S400, obtaining a target connection state corresponding to all interfaces of the switching module in the gateway device, wherein the target connection state is a connection state of the interfaces in the switching module in the gateway device obtained at intervals of a preset time length; S500, matching interface configuration of the switching module in the gateway device according to the target connection state, wherein the interface configuration of the switching module in the gateway device is a LAN port or a WAN port.
2. The method of claim 1, wherein, The target identifier is obtained in S303 by the following steps: S3031, when the target access mode is configured as DHCP and a DHCP service exists in a second network port connection segment, obtaining the target identifier as "1", wherein the judgment mode that the DHCP service exists in the second network port connection segment is that the DHCP service is detected by a udhcpc tool; S3032, when the target access mode is configured as DHCP and a DHCP service does not exist in the second network port connection segment, obtaining the target identifier as "0"; S3033, when the target access mode is configured as PPPoE and the second network port connection end exists a PPPoE service, obtaining a target identification as "1", wherein the judgment mode that the second network port connection end exists a PPPoE service is to detect by a pppoe-discovery tool; S3034, when the target access mode is configured as PPPoE and the second network port connection end does not exist a PPPoE service, obtaining a target identification as "0"; S3035, when the target access mode is configured as static IP and the second network port gateway IP is pinged, obtaining a target identification as "1", wherein the judgment mode that the second network port gateway IP is pinged is to detect the second network port gateway IP address obtained from the network configuration file by using a ping tool; S3036, when the target access mode is configured as static IP and the second network port gateway IP is not pinged, obtaining a target identification as "0".
3. The method of claim 1, wherein, In S500, the following steps are further included: S501, obtaining a first key interface ID list according to a target connection state, wherein the first key interface ID list includes a plurality of first key interface IDs, and the first key interface ID is a name corresponding to a first key interface; S502, processing the first key interface ID list by using a first processing mode to obtain an interface configuration corresponding to each first key interface ID to realize matching of the interface configuration of the switching module; S503, obtaining a second key interface ID list according to a target connection state, wherein the second key interface ID list includes a plurality of second key interface IDs, and the second key interface ID is a name corresponding to a second key interface; S504, processing the second key interface ID list by using a second processing mode to obtain an interface configuration corresponding to each second key interface ID to realize matching of the interface configuration of the switching module.
4. The method of claim 3, wherein, The first key interface is an interface connected by the target connection state from all interfaces of the switching module except the candidate interface.
5. The method of claim 3, wherein, The second key interface is an interface disconnected by the target connection state from a plurality of candidate interfaces.
6. The method of claim 3, wherein, In S502, the following steps are further included: S1, when the target variable is not an empty set, keeping the first key interface configuration unchanged to determine that the first key interface configuration is a LAN port; S2, when the target variable is an empty set, removing the first key interface corresponding to the first key interface ID from the bridge of the first network port, and simultaneously binding the first key interface configuration corresponding to the first key interface ID to a second virtual local area network and the second network port; S3, obtaining a target access mode corresponding to the second network port from a network configuration file, wherein the target access mode is a mode of the second network port accessing the Internet in the gateway device; S4, obtaining a key identification corresponding to the first key interface ID according to the target access mode; S5, when the key identification is "1", saving the first key interface ID to the target variable to obtain an interface configuration corresponding to the first key interface ID as a WAN port, wherein the target variable is a storage space for storing data. S6, when the key identification is "0", the first key interface ID corresponding to the first key interface is configured with the first virtual local area network and the first key interface ID is added to the bridge of the first network port to obtain that the interface corresponding to the first key interface ID is configured as a LAN port.
7. The method of claim 3, wherein, In S504, the following steps are further included: S5041, when the second key interface ID is consistent with the interface ID recorded in the target variable, the second key interface ID corresponding to the second key interface is configured with the first virtual local area network, the second key interface ID is added to the bridge of the first network port, and the target variable is emptied to obtain that the target network interface type corresponding to the second key interface ID is a LAN port; S5042, when the second key interface ID is inconsistent with the interface ID recorded in the target variable, the second key interface configuration is kept unchanged to determine that the second key interface is configured as a LAN port.
8. A non-transitory computer-readable storage medium, comprising: The storage medium has at least one instruction or at least one program stored therein, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the method of any one of claims 1-7.
9. An electronic device, comprising: The non-transitory computer-readable storage medium is included in the processor. The non-transitory computer-readable storage medium is included in the processor.
Citation Information
Patent Citations
Method and device for automatically recognizing LAN (Local Area Network) port and WAN (Wide Area Network) port
CN106341246A
Automatic adaption method for LAN interface and WAN interface and router
CN108667672A