Method, device, equipment and medium for allocating IP addresses based on physical network card

By parsing the physical network card information in the DHCP request message and allocating IP addresses based on it, the problem of low flexibility in IP address allocation in the existing technology is solved, enabling flexible management of clients in different areas and improving network efficiency.

CN117579598BActive Publication Date: 2024-09-17QUANXUN HUIJU NETWORK TECH BEIJING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311507243.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-13
Publication Date
2024-09-17
Estimated Expiration
2043-11-13

AI Technical Summary

Technical Problem

In the existing technology, clients cannot obtain specific IP address segments through different physical network cards, resulting in low flexibility in IP address allocation and difficulty in achieving centralized management of clients in different areas.

Method used

When the application layer issues an extension call instruction by detecting the message source, the network layer analyzes the source of the DHCP request message, obtains the physical network card information, and passes it to the application layer for analysis. It allocates IP addresses based on the physical network card name and selects the corresponding Address pool ensures that clients are assigned different address segments when accessing different physical network cards.

Benefits of technology

It improves the flexibility of IP address allocation, facilitates centralized management of clients in different areas, and prioritizes historical IP addresses for allocation, which improves network efficiency, reduces network traffic, and enhances user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117579598B
    Figure CN117579598B
Patent Text Reader

Abstract

The present application relates to the technical field of IP address allocation, and in particular to methods, devices, equipment and media for allocating IP addresses based on physical network cards. The method includes: when it is detected that the application layer issues an extended call instruction, the network layer performs message source resolution on the DHCP request message issued by the client to obtain a first DHCP request message. Then, the first DHCP request message is passed to the application layer, and the application layer performs message resolution on the first DHCP request message to obtain the name of the physical network card. Finally, an IP address is allocated based on the name of the physical network card to obtain the IP address corresponding to the client. The corresponding address pool is selected based on the physical network card connected to the client to allocate the IP address, so that when the client accesses different physical network cards, the allocated address segments are different, which improves the flexibility of IP address allocation and facilitates centralized management of clients in different areas.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of IP address allocation, and in particular to a method, apparatus, device and medium for allocating IP addresses based on a physical network card. Background Art

[0002] In a local area network, clients need to communicate with other devices in the network based on IP addresses. In related technologies, a LAN port is bound to multiple physical network cards, and an address pool is configured for the LAN interface in the DHCP service. When clients access from different physical network cards under the LAN port, the IP addresses obtained are randomly assigned from the unified address pool. However, clients cannot obtain specific address segments through different physical network cards, making IP address allocation inflexible.

[0003] Therefore, how to provide a highly flexible IP address allocation method is an urgent problem to be solved by those skilled in the art. Summary of the invention

[0004] The purpose of this application is to provide a method, device, equipment and medium for allocating IP addresses based on a physical network card, so as to solve at least one of the above technical problems.

[0005] The above invention objectives of the present application are achieved through the following technical solutions:

[0006] In a first aspect, the present application provides a method for allocating IP addresses based on a physical network card, using the following technical solution:

[0007] A method for allocating IP addresses based on a physical network card, comprising:

[0008] When detecting that the application layer issues an extended call instruction, the network layer performs message source resolution on the DHCP request message sent by the client to obtain a first DHCP request message including physical network card information;

[0009] The first DHCP request message is transmitted to the application layer, and the application layer parses the first DHCP request message to obtain a physical network card name;

[0010] An IP address is allocated based on the physical network card name to obtain an IP address corresponding to the client, wherein different physical network card names correspond to different address pools.

[0011] By adopting the above technical solution, when it is detected that the application layer issues an extended call instruction, the network layer performs message source resolution on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information. Then, the first DHCP request message is passed to the application layer, and then the application layer performs message resolution on the first DHCP request message to obtain the name of the physical network card. Finally, an IP address is allocated based on the name of the physical network card to obtain the IP address corresponding to the client. In this way, random IP address allocation is no longer based on the total address pool corresponding to the LAN interface. Instead, the corresponding address pool is selected based on the physical network card connected to the client to allocate IP addresses, so that when the client accesses different physical network cards, the allocated address segments are different, which improves the flexibility of IP address allocation and facilitates centralized management of clients in different areas.

[0012] In a preferred example, the present application may be further configured as follows: before detecting that the application layer issues an extended call instruction, the application may further include:

[0013] Obtain the DHCP request message, and perform multi-dimensional analysis on the client based on the DHCP request message to determine the network area and device type corresponding to the client;

[0014] Based on the network area, the device type and the physical network card allocation rule, the name of the physical network card to which the DHCP request message is accessed is determined.

[0015] In a preferred example, the present application may be further configured as follows: performing IP allocation based on the physical network card name to obtain the IP address corresponding to the client includes:

[0016] Perform an address pool search based on the physical network card name to determine a target address pool corresponding to the physical network card name;

[0017] Screening the allocatable IP addresses based on the allocation situation corresponding to the target address pool to determine the allocatable IP addresses;

[0018] Acquire a historical IP address usage database, and determine a historical IP address based on the historical IP address usage database and the first DHCP request message sent by the client;

[0019] IP allocation is performed based on the allocatable IP address and the historical IP address to obtain an IP address corresponding to the client.

[0020] In a preferred example, the present application may be further configured as follows: a method for determining the allocation status corresponding to the target address pool includes:

[0021] Acquire the allocation relationship between the client and the IP address in real time, and based on the first IP address corresponding to the allocation relationship, update the state of the first IP address in the target address pool to allocated in the initial allocation situation;

[0022] When an active release instruction from the client is detected, based on the second IP address in the active release instruction, updating the state of the second IP address in the target address pool to unallocated in the initial allocation situation;

[0023] The latest initial allocation situation is recorded as the allocation situation corresponding to the target address pool.

[0024] In a preferred example, the present application may be further configured as follows: after recording the latest initial allocation situation as the allocation situation corresponding to the target address pool, the configuration further includes:

[0025] Determine the lease period corresponding to each allocated IP address based on the allocation situation, and divide all allocated IP addresses based on the lease period corresponding to each allocated IP address to obtain a first allocated IP address and a second allocated IP address, wherein the first allocated IP address is an allocated IP address whose lease period reaches a first threshold, and the second allocated IP address is an allocated IP address whose lease period reaches a second threshold;

[0026] An active inquiry is performed based on the second allocated IP address, and when a response instruction is received, the allocation situation is adjusted based on the response instruction to obtain an adjusted allocation situation, wherein the active inquiry is used to inquire whether the client corresponding to the second allocated IP address still has an IP address usage demand.

[0027] In a preferred example, the present application may be further configured as follows: after allocating an IP address based on the physical network card name and obtaining the IP address corresponding to the client, the following further includes:

[0028] A DHCP response message is generated based on the IP address corresponding to the client, and the DHCP response message is sent to the client in the form of a UDP data packet, so that the client can use the IP address for network connection and data transmission.

[0029] In a preferred example, the present application may be further configured as follows: after the network layer performs message source resolution on the DHCP request message sent by the client and obtains the first DHCP request message including the physical network card information, it further includes:

[0030] The physical network card information is stored in the kernel sock structure of the network layer.

[0031] In a second aspect, the present application provides a device for allocating IP addresses based on a physical network card, which adopts the following technical solution:

[0032] A device for allocating IP addresses based on a physical network card, comprising:

[0033] A message source parsing module, configured to, when detecting that the application layer issues an extended call instruction, cause the network layer to perform message source parsing on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information;

[0034] A name parsing module, used for transmitting the first DHCP request message to the application layer, and the application layer performs message parsing on the first DHCP request message to obtain a physical network card name;

[0035] The address allocation module is used to allocate IP addresses based on the physical network card name to obtain the IP address corresponding to the client, wherein different physical network card names correspond to different address pools.

[0036] In a third aspect, the present application provides an electronic device, which adopts the following technical solution:

[0037] at least one processor;

[0038] Memory;

[0039] At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the above-mentioned method for allocating IP addresses based on a physical network card.

[0040] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution:

[0041] A computer-readable storage medium stores a computer program, which, when executed in a computer, causes the computer to execute the above-mentioned method for allocating IP addresses based on a physical network card.

[0042] In summary, the present application includes at least one of the following beneficial technical effects:

[0043] 1. When it is detected that the application layer issues an extended call instruction, the network layer parses the message source of the DHCP request message sent by the client to obtain a first DHCP request message including the physical network card information. Then, the first DHCP request message is passed to the application layer, and then the application layer parses the first DHCP request message to obtain the name of the physical network card. Finally, an IP address is allocated based on the name of the physical network card to obtain the IP address corresponding to the client. In this way, random IP address allocation is no longer based on the total address pool corresponding to the LAN interface. Instead, the corresponding address pool is selected based on the physical network card connected to the client to allocate IP addresses, so that when the client connects to different physical network cards, the allocated address segments are different, which improves the flexibility of IP address allocation and facilitates centralized management of clients in different areas.

[0044] 2. Perform an address pool search based on the physical network card name to determine the target address pool corresponding to the physical network card name, and screen the allocatable IP addresses based on the allocation of the target address pool to determine the allocatable IP addresses. Then, determine the historical IP address based on the historical IP address usage database and the first DHCP request message sent by the client, perform IP allocation based on the allocatable IP address and the historical IP address, and obtain the IP address corresponding to the client. Giving priority to the historical IP addresses used by the client for address allocation can improve network efficiency, reduce network traffic, and enhance user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is a schematic diagram of the IP address allocation of a client accessing a physical network card in the related technology of one embodiment of the present application;

[0046] Figure 2 It is a schematic diagram of the IP address allocation of the client accessing the physical network card in the present application in one embodiment of the present application;

[0047] Figure 3 It is a flowchart of a method for allocating IP addresses based on a physical network card according to one embodiment of the present application;

[0048] Figure 4 This is a schematic diagram of the system architecture of a method for allocating IP addresses based on a physical network card according to one embodiment of the present application;

[0049] Figure 5 It is a structural diagram of a device for allocating IP addresses based on a physical network card according to one embodiment of the present application;

[0050] Figure 6 It is a structural schematic diagram of an electronic device according to one embodiment of the present application. DETAILED DESCRIPTION

[0051] The following combination Figures 1 to 6 This application is described in further detail.

[0052] This specific embodiment is merely an explanation of the present application and is not a limitation of the present application. After reading this specification, a person skilled in the art may make non-creative modifications to the present embodiment as needed, but such modifications are protected by the patent law as long as they are within the scope of the present application.

[0053] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are 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 without creative work are within the scope of protection of this application.

[0054] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.

[0055] The embodiments of the present application are further described in detail below in conjunction with the drawings in the specification.

[0056] In the related art, an address pool is configured for the LAN interface, and multiple physical network cards are bound to the LAN interface. When an IP address is allocated to a client connected to any physical network card in the LAN interface, an idle IP address is randomly selected from the address pool corresponding to the LAN interface. The client cannot obtain a specific address segment through different physical network cards, which makes the flexibility of IP address allocation low. Figure 1 As shown, Figure 1 It shows the IP address allocation after the client accesses the physical network card in the related technology. Figure 1 The address pool corresponding to the LAN interface is: 192.168.1.1-192.168.1.254, pc1, pc2 and pc3 represent three clients respectively, eth0, eth1, eth2 and eth3 represent four physical network cards respectively, and the IP addresses assigned to pc1, pc2 and pc3 are randomly selected from the address segment: 192.168.1.1-192.168.1.254.

[0057] In order to solve the problem of low flexibility in IP address allocation in related technologies, the embodiment of the present application provides a method for allocating IP addresses based on physical network cards. When a LAN interface is bound to multiple physical network cards, different address pools are divided for different physical network cards. When a client accesses a physical network card, an IP address is allocated from the address pool corresponding to the physical network card. The client can obtain specific address segments through different physical network cards, thereby improving the flexibility of IP address allocation. Figure 2 As shown, Figure 2 It shows the IP address allocation after the client accesses the physical network card in this application, that is, the client pc1 accesses the physical network card eth0, and the IP address is randomly allocated from the address segment: 192.168.1.1-192.168.1.100; the client pc2 accesses the physical network card eth1, and the IP address is randomly allocated from the address segment: 192.168.1.101-192.168.1.200; the client pc3 accesses the physical network card eth2, and the IP address is randomly allocated from the address segment: 192.168.1.201-192.168.1.254.

[0058] The embodiment of the present application provides a method for allocating IP addresses based on a physical network card, which is executed by an electronic device, which can be a server or a terminal device, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiment of the present application. Figure 3 As shown, the method includes step S101, step S102 and step S103, wherein:

[0059] Step S101: When detecting that the application layer issues an extended call instruction, the network layer performs message source resolution on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information.

[0060] For the embodiment of the present application, a setsockopt option is extended in the application layer. After the setsockopt option is turned on, the application layer will pass the real physical network card information from the network layer to the upper layer application when receiving the DHCP request message. When the application layer turns on the setsockopt option, the application layer will issue an extended call instruction to the network layer. The extended call instruction is used to notify the network layer to pass the physical network card information to the application. Therefore, the network layer performs message source resolution for the DHCP request message sent by the client to obtain a first DHCP request message including physical network card information, wherein the physical network card information is used to characterize the detailed information of the physical network card requested by the client. In the embodiment of the present application, a network module is added to the network driver of the network layer, and the network module is used to parse the physical network card information in the DHCP request message. Preferably, after parsing the physical network card information, the physical network card information is stored in the kernel sock structure to obtain a sock structure carrying the physical network card information.

[0061] Step S102: delivering the first DHCP request message to the application layer, and the application layer parses the first DHCP request message to obtain the name of the physical network card.

[0062] For the embodiment of the present application, the network layer transmits the first DHCP request message carrying the physical network card information to the application layer, and then the application layer performs message parsing on the first DHCP request message to obtain the name of the physical network card accessed by the client. Since the first DHCP request message includes the physical network card information, the application layer obtains the network card name of the physical network card accessed by the client by performing message parsing on the first DHCP request message carrying the physical network card information.

[0063] Step S103: Allocate an IP address based on the physical network card name to obtain an IP address corresponding to the client, wherein different physical network card names correspond to different address pools.

[0064] For the embodiment of the present application, when the LAN interface is bound to multiple physical network cards, the total address pool corresponding to the LAN interface is divided into each physical network card under the LAN interface to obtain the address pool corresponding to each physical network card. For example, the LAN interface includes four physical network cards: eth0, eth1, eth2, and eth3. The total address pool corresponding to the LAN interface is: 192.168.1.1-192.168.1.254. After the address segment is divided, the address pool of the physical network card named eth0 is determined to be: 192.168.1.1-192.168.1.100, the address pool of the physical network card named eth1 is: 192.168.1.101-192.168.1.200, the address pool of the physical network card named eth2 is: 192.168.1.201-192.168.1.254, and the physical network card named eth3 has no assigned address segment. Then, based on the name of the physical network card, an address pool corresponding to it is selected, and an IP address is selected from the address pool and assigned to the client to complete the IP address allocation based on the physical network card. In the embodiment of the present application, random IP address allocation is no longer performed based on the total address pool corresponding to the LAN interface, but the corresponding address pool is selected based on the physical network card connected to the client to perform IP address allocation, so that when the client connects to different physical network cards, the allocated address segments are different, which improves the flexibility of IP address allocation and facilitates centralized management of clients in different areas.

[0065] like Figure 4 As shown, Figure 4 This is a hierarchical architecture diagram of a method for allocating IP addresses based on a physical network card. In an embodiment of the present application, a network module is added to the network driver, the network module is used to analyze the DHCP request message to obtain the real physical network card information, and store the physical network card information in the kernel sock structure, and a setsockopt option is added to the application layer. Turning on the setsockopt option is used to notify the network layer to pass the physical network card information to the application.

[0066] It can be seen that in an embodiment of the present application, when it is detected that the application layer issues an extended call instruction, the network layer performs message source resolution on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information. Then, the first DHCP request message is passed to the application layer, and then the application layer performs message resolution on the first DHCP request message to obtain the name of the physical network card. Finally, an IP address is allocated based on the name of the physical network card to obtain the IP address corresponding to the client. In this way, random IP address allocation is no longer based on the total address pool corresponding to the LAN interface. Instead, the corresponding address pool is selected based on the physical network card connected to the client to allocate IP addresses, so that when the client accesses different physical network cards, the allocated address segments are different, which improves the flexibility of IP address allocation and facilitates centralized management of clients in different areas.

[0067] Further, in order to more reasonably allocate network resources, avoid resource waste and performance bottlenecks, and optimize network performance and resource utilization, in the embodiment of the present application, before detecting that the application layer issues an extended call instruction, it also includes:

[0068] Obtain DHCP request messages, perform multi-dimensional analysis on the client based on the DHCP request messages, and determine the network area and device type corresponding to the client;

[0069] Based on the network area, device type, and physical network card allocation rules, determine the name of the physical network card to which the DHCP request message is connected.

[0070] For the embodiment of the present application, in order to be able to manage clients of different network areas and device types, when the client accesses the physical network card, the network area and device type of the client will be comprehensively considered to facilitate the client management work. The DHCP request message includes but is not limited to: hardware address, hardware type, hardware address length, number of hops, transaction ID, number of seconds, flags, client IP address, server IP address, gateway IP address, hardware type option, domain name option, domain name server option and host name option and other information. Then, based on the DHCP request message, the client is subjected to multi-dimensional analysis to determine the network area and device type corresponding to the client, for example, based on the MAC address segment of the hardware address, the network area to which the client belongs is determined; based on the hardware type and hardware address length, the device type of the client is determined. At the same time, the correspondence between the network area, device type and physical network card name is pre-stored in the electronic device, recorded as the physical network card allocation rule, which is set by the technician according to actual needs, and the user can also adjust it based on the actual situation. In this regard, the embodiment of the present application is no longer limited. Finally, the network area, device type and physical network card allocation rules corresponding to the client are matched, and the name of the successfully matched physical network card is recorded as the name of the physical network card accessed by the DHCP request message. When the client accesses the physical network card, the network area and device type factors are comprehensively considered to allocate network resources more reasonably, avoid resource waste and performance bottlenecks, and optimize network performance and resource utilization.

[0071] It can be seen that in the embodiment of the present application, a multi-dimensional analysis is performed on the client based on the DHCP request message to determine the network area and device type corresponding to the client, and then the name of the physical network card to which the DHCP request message is accessed is determined based on the network area, device type and physical network card allocation rules. When the client accesses the physical network card, the network area and device type factors are comprehensively considered to allocate network resources more reasonably, avoid resource waste and performance bottlenecks, and optimize network performance and resource utilization.

[0072] Further, in order to improve network efficiency, reduce network traffic and enhance user experience, in an embodiment of the present application, IP allocation is performed based on the physical network card name to obtain the IP address corresponding to the client, including:

[0073] Perform an address pool search based on the physical network card name to determine the target address pool corresponding to the physical network card name;

[0074] Screen the allocatable IP addresses based on the allocation status of the target address pool to determine the allocatable IP addresses;

[0075] Acquire a historical IP address usage database, and determine a historical IP address based on the historical IP address usage database and a first DHCP request message sent by the client;

[0076] Perform IP allocation based on the allocatable IP addresses and historical IP addresses to obtain the IP address corresponding to the client.

[0077] For the embodiment of the present application, since multiple physical network cards are bound under the LAN interface, there is a corresponding address pool for each physical network card, so multiple address pools are pre-stored in the electronic device. When allocating IP addresses, clients accessing different physical network cards need to select IP addresses in the corresponding address pools. Therefore, the address pool is searched based on the physical network card name to determine the target address pool corresponding to the physical network card name. However, not every IP address in the target address pool is idle. There are also some IP addresses that have been allocated to other clients in the address pool, which are recorded as allocated IP addresses. In addition to the allocated IP addresses, the rest of the address pool is called allocable IP addresses. There are many ways to determine the allocation situation corresponding to the target address pool. In one achievable way, the allocation situation is determined based on the DHCP server log record, wherein the DHCP server log records which client the IP address is allocated to, the allocation time, the client MAC address, etc. In another achievable way, a network monitoring tool is used to monitor the IP address allocation situation in the network in real time. For example, the Nmap tool is used to scan the IP addresses in the network, and check which IP addresses have been used and which IP addresses are available, and then determine the allocation situation corresponding to the target address pool. Of course, other methods can also be used to determine the allocation situation corresponding to the target address pool, and this embodiment of the present application will no longer limit this. Then, obtain a historical IP address usage database, which records all past usage situations of IP addresses, that is, the hardware address corresponding to which client the IP address was assigned to in the past, and then, based on the hardware address in the first DHCP request message sent by the client and the historical IP address usage database, perform address matching, and record the IP address that successfully matches the hardware address in the historical IP address usage database as the IP address corresponding to the client. When no data in the hardware address matches the historical IP address usage database successfully, a random selection is made from the allocable IP addresses to determine the IP address corresponding to the client. Giving priority to the historical IP addresses used by the client for address allocation can improve network efficiency, reduce network traffic, and enhance user experience.

[0078] It can be seen that in the embodiment of the present application, an address pool search is performed based on the physical network card name, the target address pool corresponding to the physical network card name is determined, and the allocatable IP address is screened based on the allocation situation corresponding to the target address pool to determine the allocatable IP address. Then, based on the historical IP address usage database and the first DHCP request message sent by the client, the historical IP address is determined, and IP allocation is performed based on the allocatable IP address and the historical IP address to obtain the IP address corresponding to the client. Giving priority to the historical IP address used by the client for address allocation can improve network efficiency, reduce network traffic and enhance user experience.

[0079] Further, in order to ensure the accuracy of the allocatable IP addresses, in the embodiment of the present application, the method of determining the allocation status corresponding to the target address pool includes:

[0080] Acquire the allocation relationship between the client and the IP address in real time, and based on the first IP address corresponding to the allocation relationship, update the state of the first IP address in the target address pool to allocated in the initial allocation situation;

[0081] When an active release instruction from the client is detected, based on the second IP address in the active release instruction, updating the state of the second IP address in the target address pool to unallocated in the initial allocation situation;

[0082] The latest initial allocation situation is recorded as the allocation situation corresponding to the target address pool.

[0083] For the embodiment of the present application, the client described in the process refers to any client in the local area network. Since the IP address assigned by the client has a lease, the lease expires or the client actively releases it, which will restore the IP address to an unallocated state. The allocation situation corresponding to the target address pool changes in real time with the IP address lease and the client's active release. Therefore, the allocation relationship between the client and the IP address is obtained in real time, and based on the first IP address corresponding to the allocation relationship, the state of the first IP address in the target address pool is updated to allocated in the initial allocation situation, wherein the first IP address is the IP address that has been matched to the client, indicating that the IP address has been allocated, and the initial initial allocation situation is that each IP address in the target address pool is unallocated, that is, the state of the first IP address is changed to allocated based on the initial allocation situation. At the same time, it is also necessary to detect whether the client actively releases the IP address at all times. When the active release instruction sent by the client is detected, it indicates that the second IP address in the active release instruction is no longer occupied, so the state of the second IP address in the target address pool is updated to unallocated in the initial allocation situation. In order to ensure the accuracy of the allocatable IP addresses, when the allocatable IP addresses are screened based on the allocation status corresponding to the target address pool, the initial allocation status of the latest version is recorded as the allocation status corresponding to the target address pool.

[0084] It can be seen that in an embodiment of the present application, when an active release instruction from the client is detected, based on the second IP address in the active release instruction, the status of the second IP address in the target address pool is updated to unallocated in the initial allocation situation. In order to ensure the accuracy of the allocable IP address, the latest initial allocation situation is recorded as the allocation situation corresponding to the target address pool.

[0085] Furthermore, in order to release the IP address in time when it is not needed and avoid wasting the IP address, in the embodiment of the present application, after recording the latest initial allocation as the allocation corresponding to the target address pool, the following is also included:

[0086] Determine the lease period corresponding to each allocated IP address based on the allocation situation, and divide all allocated IP addresses based on the lease period corresponding to each allocated IP address to obtain a first allocated IP address and a second allocated IP address, wherein the first allocated IP address is an allocated IP address whose lease period reaches a first threshold, and the second allocated IP address is an allocated IP address whose lease period reaches a second threshold;

[0087] An active inquiry is performed based on the second allocated IP address, and when a response instruction is received, the allocation situation is adjusted based on the response instruction to obtain an adjusted allocation situation, wherein the active inquiry is used to inquire whether the client corresponding to the second allocated IP address still has an IP address usage demand.

[0088] For the embodiments of the present application, each IP address allocated to a client has a lease period, and the client's use of the IP address is not long-term. In order to improve the efficiency of IP address use, different response measures are taken for allocated IP addresses with different lease periods, and active inquiries are made for allocated IP addresses whose lease period reaches a second threshold. The IP address can be released in time when it is no longer needed, avoiding waste of IP addresses.

[0089] Specifically, based on each allocated IP address in the allocation situation, the lease period corresponding to each allocated IP address is determined, and all allocated IP addresses are divided based on the lease period corresponding to each allocated IP address, and the first allocated IP address whose lease period reaches the first threshold and the second allocated IP address whose lease period reaches the second threshold are determined. Preferably, the first threshold is 50% and the second threshold is 85%. The first allocated IP address whose lease period has reached 50% is marked, and the mark is used to increase the attention of the electronic device to the first allocated IP address whose lease period has reached 50%. When the IP address sends a renewal request, it is given priority to respond. The second allocated IP address whose lease period has reached 85% is actively queried, and the active inquiry is used to confirm whether the second allocated IP address has a renewal requirement. When the second allocated IP address indicates that there is no renewal requirement, the renewal request of the second allocated IP address is no longer monitored. When the second allocated IP address indicates that there is a renewal requirement, it is given priority to respond when the renewal request of the second allocated IP address is detected.

[0090] It can be seen that in the embodiment of the present application, the lease corresponding to each allocated IP address is determined based on the allocation situation, and all allocated IP addresses are divided based on the lease corresponding to each allocated IP address to obtain a first allocated IP address and a second allocated IP address. Then, an active inquiry is made based on the second allocated IP address, and when a response instruction is received, the allocation situation is adjusted based on the response instruction to obtain the adjusted allocation situation. Different response measures are taken for allocated IP addresses with different leases, and an active inquiry is made for allocated IP addresses whose lease reaches the second threshold, so that the IP address can be released in time when it is not needed, thereby avoiding waste of IP addresses.

[0091] Further, in the embodiment of the present application, after the IP address is allocated based on the physical network card name and the IP address corresponding to the client is obtained, the following is further included:

[0092] A DHCP response message is generated based on the IP address corresponding to the client, and is sent to the client in the form of a UDP data packet, so that the client can use the IP address for network connection and data transmission.

[0093] For the embodiment of the present application, after determining the IP address corresponding to the client, the IP address needs to be sent to the client so that the client can use the IP address for network connection and data transmission. Therefore, according to the provisions of the DHCP protocol and the IP address corresponding to the client, a DHCP response message is generated, wherein the DHCP response message includes: the IP address assigned to the client, the subnet mask, the default gateway, the DNS server and other network configuration parameters. The process of generating a DHCP response message can be achieved by writing a network application. Of course, it can also be completed using existing DHCP server software. Then, the generated DHCP response message is encapsulated in a UDP data packet and sent to the client through the network interface, wherein the destination address of the UDP data packet is the hardware address of the client, and the destination port is the port number specified by the DHCP protocol (usually 68).

[0094] It can be seen that in the embodiment of the present application, a DHCP response message is generated based on the IP address corresponding to the client, and the DHCP response message is sent to the client in the form of a UDP data packet, so that the client can use the IP address for network connection and data transmission.

[0095] Further, in order to help the operating system correctly process the request at the network layer, in an embodiment of the present application, the network layer performs message source resolution on the DHCP request message sent by the client, and after obtaining the first DHCP request message including the physical network card information, it also includes:

[0096] Store the physical network card information in the kernel sock structure of the network layer.

[0097] For the embodiment of the present application, after obtaining the first DHCP request message including the physical network card information, storing the physical network card information in the kernel sock structure of the network layer can help the operating system to correctly process the request at the network layer. For example, the operating system can determine which network interface to forward the request to based on the target IP address in the message, or determine the source of the request based on the source IP address in the message. In addition, storing the DHCP request message can also help the operating system track and manage network connections so as to release IP addresses or other network resources when needed. In short, storing the physical network card information in the sock structure helps the operating system to process and forward the request at the network layer and manage network connections.

[0098] It can be seen that in the embodiment of the present application, the physical network card information is stored in the kernel sock structure of the network layer to help the operating system correctly process the request at the network layer.

[0099] The above embodiment introduces a method for allocating IP addresses based on a physical network card from the perspective of a method flow, and the following embodiment introduces a device for allocating IP addresses based on a physical network card from the perspective of a virtual module or a virtual unit. For details, please refer to the following embodiment.

[0100] The embodiment of the present application provides a device for allocating IP addresses based on a physical network card, such as Figure 5 As shown, the device for allocating IP addresses based on a physical network card may specifically include:

[0101] The message source parsing module 210 is used for, when detecting that the application layer issues an extended call instruction, the network layer performs message source parsing on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information;

[0102] The name resolution module 220 is used to transmit the first DHCP request message to the application layer, and the application layer performs message resolution on the first DHCP request message to obtain the name of the physical network card;

[0103] The address allocation module 230 is used to allocate IP addresses based on the physical network card name to obtain the IP address corresponding to the client, wherein different physical network card names correspond to different address pools.

[0104] For the embodiment of the present application, when the message source resolution module 210 detects that the application layer issues an extended call instruction, the network layer performs message source resolution on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information. Then, the name resolution module 220 passes the first DHCP request message to the application layer, and then the application layer performs message resolution on the first DHCP request message to obtain the name of the physical network card. Finally, the address allocation module 230 performs IP address allocation based on the physical network card name to obtain the IP address corresponding to the client. In this way, random IP address allocation is no longer performed based on the total address pool corresponding to the LAN interface. Instead, the corresponding address pool is selected based on the physical network card connected to the client to perform IP address allocation, so that when the client connects to different physical network cards, the allocated address segments are different, which improves the flexibility of IP address allocation and facilitates centralized management of clients in different areas.

[0105] A possible implementation of the embodiment of the present application is a device for allocating IP addresses based on a physical network card, further comprising:

[0106] The physical network card selection module is used to obtain the DHCP request message, perform multi-dimensional analysis on the client based on the DHCP request message, and determine the network area and device type corresponding to the client;

[0107] Based on the network area, device type, and physical network card allocation rules, determine the name of the physical network card to which the DHCP request message is connected.

[0108] In a possible implementation of the embodiment of the present application, when the address allocation module 230 performs IP allocation based on the physical network card name to obtain the IP address corresponding to the client, it is used to:

[0109] Perform an address pool search based on the physical network card name to determine the target address pool corresponding to the physical network card name;

[0110] Screen the allocatable IP addresses based on the allocation status of the target address pool to determine the allocatable IP addresses;

[0111] Acquire a historical IP address usage database, and determine a historical IP address based on the historical IP address usage database and a first DHCP request message sent by the client;

[0112] Perform IP allocation based on the allocatable IP addresses and historical IP addresses to obtain the IP address corresponding to the client.

[0113] A possible implementation of the embodiment of the present application is to determine the allocation status corresponding to the target address pool, including:

[0114] Acquire the allocation relationship between the client and the IP address in real time, and based on the first IP address corresponding to the allocation relationship, update the state of the first IP address in the target address pool to allocated in the initial allocation situation;

[0115] When an active release instruction from the client is detected, based on the second IP address in the active release instruction, updating the state of the second IP address in the target address pool to unallocated in the initial allocation situation;

[0116] The latest initial allocation situation is recorded as the allocation situation corresponding to the target address pool.

[0117] A possible implementation of the embodiment of the present application is a device for allocating IP addresses based on a physical network card, further comprising:

[0118] A lease monitoring module, used to determine the lease corresponding to each allocated IP address based on the allocation situation, and divide all allocated IP addresses based on the lease corresponding to each allocated IP address to obtain a first allocated IP address and a second allocated IP address, wherein the first allocated IP address is an allocated IP address whose lease reaches a first threshold, and the second allocated IP address is an allocated IP address whose lease reaches a second threshold;

[0119] An active inquiry is performed based on the second allocated IP address, and when a response instruction is received, the allocation situation is adjusted based on the response instruction to obtain an adjusted allocation situation, wherein the active inquiry is used to inquire whether the client corresponding to the second allocated IP address still has an IP address usage demand.

[0120] A possible implementation of the embodiment of the present application is a device for allocating IP addresses based on a physical network card, further comprising:

[0121] The response transmission module is used to generate a DHCP response message based on the IP address corresponding to the client, and send the DHCP response message to the client in the form of a UDP data packet, so that the client can use the IP address for network connection and data transmission.

[0122] A possible implementation of the embodiment of the present application is a device for allocating IP addresses based on a physical network card, further comprising:

[0123] The network card information storage module is used to store the physical network card information in the kernel sock structure of the network layer.

[0124] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0125] An electronic device is provided in an embodiment of the present application, such as Figure 6 As shown, Figure 6 The electronic device 300 shown includes: a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the electronic device 300 may also include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the electronic device 300 does not constitute a limitation on the embodiments of the present application.

[0126] The processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0127] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but it does not mean that there is only one bus or only one type of bus.

[0128] The memory 303 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.

[0129] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.

[0130] The electronic devices include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and fixed terminals such as digital TVs, desktop computers, etc. It can also be a server, etc. Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0131] The embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and when it is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment. Compared with the related art, in the embodiment of the present application, when it is detected that the application layer issues an extended call instruction, the network layer performs message source analysis on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information. Then, the first DHCP request message is passed to the application layer, and then the application layer performs message analysis on the first DHCP request message to obtain the name of the physical network card. Finally, an IP address is allocated based on the name of the physical network card to obtain the IP address corresponding to the client. In this way, random IP address allocation is no longer performed based on the total address pool corresponding to the LAN interface, but the corresponding address pool is selected based on the physical network card connected to the client for IP address allocation, so that the client accesses different physical network cards and the allocated address segments are different, which improves the flexibility of IP address allocation and facilitates centralized management of clients in different areas.

[0132] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0133] The above are only some implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for allocating IP addresses based on a physical network card, characterized in that: The LAN interface includes multiple physical network cards for client access, including: When detecting that the application layer issues an extended call instruction, the network layer performs message source resolution on the DHCP request message issued by the client to obtain a first DHCP request message including physical network card information, wherein the physical network card information is used to represent relevant information corresponding to the physical network card connected to the client; The first DHCP request message is transmitted to the application layer, and the application layer parses the first DHCP request message to obtain a physical network card name, wherein the physical network card name is a name corresponding to the physical network card connected to the client under the LAN interface; An IP address is allocated based on the physical network card name to obtain an IP address corresponding to the client, wherein different physical network card names correspond to different address pools.

2. The method for allocating IP addresses based on a physical network card according to claim 1, characterized in that: Also includes: Obtain the DHCP request message, and perform multi-dimensional analysis on the client based on the DHCP request message to determine the network area and device type corresponding to the client; Based on the network area, the device type and the physical network card allocation rule, the name of the physical network card to which the DHCP request message is accessed is determined.

3. The method for allocating IP addresses based on a physical network card according to claim 1, characterized in that: The step of allocating an IP address based on the physical network card name to obtain an IP address corresponding to the client includes: Perform an address pool search based on the physical network card name to determine a target address pool corresponding to the physical network card name; Screening the allocatable IP addresses based on the allocation situation corresponding to the target address pool to determine the allocatable IP addresses; Acquire a historical IP address usage database, and determine a historical IP address based on the historical IP address usage database and the first DHCP request message sent by the client; IP allocation is performed based on the allocatable IP address and the historical IP address to obtain an IP address corresponding to the client.

4. The method for allocating IP addresses based on a physical network card according to claim 3, characterized in that: The method of determining the allocation status corresponding to the target address pool includes: Acquire the allocation relationship between the client and the IP address in real time, and based on the first IP address corresponding to the allocation relationship, update the state of the first IP address in the target address pool to allocated in the initial allocation situation; When an active release instruction from the client is detected, based on the second IP address in the active release instruction, updating the state of the second IP address in the target address pool to unallocated in the initial allocation situation; The latest initial allocation situation is recorded as the allocation situation corresponding to the target address pool.

5. The method for allocating IP addresses based on a physical network card according to claim 4, characterized in that: After recording the latest initial allocation situation as the allocation situation corresponding to the target address pool, the method further includes: Determine the lease period corresponding to each allocated IP address based on the allocation situation, and divide all allocated IP addresses based on the lease period corresponding to each allocated IP address to obtain a first allocated IP address and a second allocated IP address, wherein the first allocated IP address is an allocated IP address whose lease period reaches a first threshold, and the second allocated IP address is an allocated IP address whose lease period reaches a second threshold; An active inquiry is performed based on the second allocated IP address, and when a response instruction is received, the allocation situation is adjusted based on the response instruction to obtain an adjusted allocation situation, wherein the active inquiry is used to inquire whether the client corresponding to the second allocated IP address still has an IP address usage demand.

6. The method for allocating IP addresses based on a physical network card according to claim 1, characterized in that: After allocating an IP address based on the physical network card name and obtaining the IP address corresponding to the client, the method further includes: A DHCP response message is generated based on the IP address corresponding to the client, and the DHCP response message is sent to the client in the form of a UDP data packet, so that the client can use the IP address for network connection and data transmission.

7. The method for allocating IP addresses based on a physical network card according to claim 1, characterized in that: The network layer performs message source resolution on the DHCP request message sent by the client to obtain the first DHCP request message including the physical network card information, and further includes: The physical network card information is stored in the kernel sock structure of the network layer.

8. A device for allocating IP addresses based on a physical network card, characterized in that: include: A message source parsing module, configured to, when detecting that the application layer issues an extended call instruction, cause the network layer to perform message source parsing on the DHCP request message issued by the client, and obtain a first DHCP request message including physical network card information, wherein the physical network card information is used to represent relevant information corresponding to the physical network card connected to the client; A name parsing module, configured to transmit the first DHCP request message to the application layer, and the application layer parses the first DHCP request message to obtain a physical network card name, wherein the physical network card name is a name corresponding to the physical network card accessed by the client under the LAN interface; The address allocation module is used to allocate IP addresses based on the physical network card name to obtain the IP address corresponding to the client, wherein different physical network card names correspond to different address pools.

9. An electronic device, characterized in that: include: at least one processor; Memory; At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the method for allocating IP addresses based on a physical network card as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed in a computer, the computer is caused to execute the method for allocating IP addresses based on a physical network card as claimed in any one of claims 1 to 7.