CN115297028B - Network card connectivity detection method and device, electronic device and storage medium - Google Patents

Network card connectivity detection method and device, electronic device and storage medium Download PDF

Info

Publication number
CN115297028B
CN115297028B CN202211219332.XA CN202211219332A CN115297028B CN 115297028 B CN115297028 B CN 115297028B CN 202211219332 A CN202211219332 A CN 202211219332A CN 115297028 B CN115297028 B CN 115297028B
Authority
CN
China
Prior art keywords
network card
tested
gateway
address
socket
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202211219332.XA
Other languages
Chinese (zh)
Other versions
CN115297028A (en
Inventor
陈梁
袁文君
周郃
李芳芳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Dahua Technology Co Ltd
Original Assignee
Zhejiang Dahua Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Dahua Technology Co Ltd filed Critical Zhejiang Dahua Technology Co Ltd
Priority to CN202211219332.XA priority Critical patent/CN115297028B/en
Publication of CN115297028A publication Critical patent/CN115297028A/en
Application granted granted Critical
Publication of CN115297028B publication Critical patent/CN115297028B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0805Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
    • H04L43/0811Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking connectivity

Landscapes

  • Engineering & Computer Science (AREA)
  • Environmental & Geological Engineering (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The application relates to a network card connectivity detection method, a network card connectivity detection device, an electronic device and a storage medium, wherein the network card connectivity detection method comprises the following steps: determining a gateway MAC address of a network card to be tested and an IP address of a target server; generating a test request based on the gateway MAC address and the target server IP address; sending the test request to a gateway of the network card to be tested through the socket so that the gateway of the network card to be tested forwards the test request to the target server; and receiving feedback information forwarded by the gateway of the network card to be tested, and determining the connectivity of the network card to be tested and the target server based on the feedback information. By the method and the device, the problem that normal communication service is interrupted when the connectivity of the network card is detected is solved, and the connectivity test of the network card is realized.

Description

Network card connectivity detection method and device, electronic device and storage medium
Technical Field
The present application relates to the field of network communication technologies, and in particular, to a network card connectivity detection method, apparatus, electronic apparatus, and storage medium.
Background
With the continuous improvement of network communication technology, many terminal devices may have multiple network cards, such as ethernet, mobile network, and wireless communication network, so that the terminal devices can communicate with the server through the multiple network cards. When a plurality of network cards exist, one of the network cards is usually selected as a default network card, and the other network cards can be used as standby network cards.
Generally, one network card is selected to communicate with a server through a route in a terminal device, when the terminal device needs to detect connectivity of other standby network cards and the server in a process of service communication with the server through a default network card, a gateway of the default network card needs to be disconnected with the server through the route, and a gateway of the other standby network cards needs to be selected to perform communication detection with the server, so that communication established between the default network card and the server can be disabled through communication detection of the network cards in the mode, service interruption is caused, and normal service communication is influenced.
For the problem that normal communication service is interrupted when network card connectivity detection is performed in the related art, no effective solution is provided at present.
Disclosure of Invention
The present embodiment provides a method and an apparatus for detecting connectivity of a network card, an electronic apparatus, and a storage medium, so as to solve the problem that, in the related art, when detecting connectivity of a network card, normal communication service is interrupted.
In a first aspect, in this embodiment, a method for detecting connectivity of a network card is provided, including:
determining a gateway MAC address of a network card to be tested and an IP address of a target server;
generating a test request based on the gateway MAC address and the target server IP address;
sending the test request to the gateway of the network card to be tested through a socket so that the gateway of the network card to be tested forwards the test request to the target server;
and receiving feedback information forwarded by the gateway of the network card to be tested, and determining the connectivity of the network card to be tested and the target server based on the feedback information, wherein the feedback information is generated by the target server based on the test request.
In some embodiments, the determining the gateway MAC address of the network card to be tested includes:
determining a gateway IP address of the network card to be tested;
determining the gateway MAC address based on the gateway IP address.
In some of these embodiments, said determining said gateway MAC address based on said gateway IP address comprises:
determining the gateway MAC address based on an address resolution protocol and the gateway IP address.
In some of these embodiments, said generating a test request based on said gateway MAC address and said target server IP address comprises:
creating a socket based on the network protocol type of the network card to be tested;
performing configuration operation on the socket to obtain a target socket, wherein the configuration operation comprises binding the socket with the network card to be tested and configuring the socket not to pass through routing selection;
binding the IP address of the target server and the MAC address of the gateway into a preset address resolution protocol to obtain a bound address resolution protocol;
and generating the test request based on the bound address resolution protocol and the target socket.
In some embodiments, the sending the test request to the gateway of the network card to be tested through the socket includes:
and sending the test request to the gateway of the network card to be tested through the target socket.
In some embodiments, the receiving feedback information forwarded by the gateway of the network card to be tested, and determining connectivity between the network card to be tested and the target server based on the feedback information includes:
if the feedback information forwarded by the gateway is received within a preset time, the connectivity between the network card to be tested and the target server is normal;
and if the feedback information forwarded by the gateway is not received within the preset time, the connectivity between the network card to be tested and the target server is abnormal.
In some embodiments of the foregoing, after determining connectivity between the network card to be tested and the target server based on the feedback information, the method further includes:
and if the connectivity between the network card to be tested and the target server is abnormal, outputting an abnormal prompt.
In a second aspect, in this embodiment, a device for detecting connectivity of a network card is provided, including:
the determining module is used for determining the gateway MAC address of the network card to be tested and the IP address of the target server;
a generation module for generating a test request based on the gateway MAC address and the target server IP address;
the sending module is used for sending the test request to the gateway of the network card to be tested through a socket so that the gateway of the network card to be tested forwards the test request to the target server;
and the connectivity detection module is used for receiving feedback information forwarded by the gateway of the network card to be tested and determining the connectivity of the network card to be tested and the target server based on the feedback information, wherein the feedback information is generated by the target server based on the test request.
In a third aspect, in this embodiment, an electronic apparatus is provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the computer program, the network card connectivity detection method according to the first aspect is implemented.
In a fourth aspect, in the present embodiment, a storage medium is provided, on which a computer program is stored, and the program, when executed by a processor, implements the network card connectivity detection method according to the first aspect.
Compared with the related art, in the network card connectivity detection method provided in this embodiment, the gateway MAC address of the network card to be detected and the IP address of the target server are determined, and the test request is generated according to the gateway MAC address of the network card to be detected and the IP address of the target server, and further, the test request is sent to the gateway of the network card to be detected in a socket connection manner, so that the gateway of the network card to be detected forwards the test request to the target server, and thus the network card to be detected does not need to be selected in a routing manner, that is, when detecting connectivity of the network card to be detected in a process of service communication between a default network card and the server, communication between the default network card and the server does not need to be disconnected by a router, and thus, normal communication of services is ensured in a network card connectivity detection process. Furthermore, the connectivity between the network card to be tested and the target server is determined according to the feedback information forwarded by the gateway of the network card to be tested, so that the connectivity detection result between the network card to be tested and the target server can be conveniently determined.
The details of one or more embodiments of the application are set forth in the accompanying drawings and the description below to provide a more thorough understanding of the application.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a block diagram of a hardware structure of a terminal of a network card connectivity detection method according to an embodiment of the present disclosure;
fig. 2 is a flowchart of a network card connectivity detection method provided in the embodiment of the present application;
fig. 3 is a flowchart of another method for detecting connectivity of a network card according to an embodiment of the present disclosure;
FIG. 4 is a schematic structural diagram of a test request packet according to an embodiment of the present application;
fig. 5 is a block diagram of a structure of a device for detecting connectivity of a network card according to an embodiment of the present disclosure.
Detailed Description
For a clearer understanding of the objects, technical solutions and advantages of the present application, reference is made to the following description and accompanying drawings.
Unless defined otherwise, technical or scientific terms used herein shall have the same general meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The use of the terms "a" and "an" and "the" and similar referents in the context of describing the invention (including a reference to the context of the specification and claims) are to be construed to cover both the singular and the plural, as well as the singular and plural. The terms "comprises," "comprising," "has," "having," and any variations thereof, as referred to in this application, are intended to cover non-exclusive inclusions; for example, a process, method, and system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or modules, but may include other steps or modules (elements) not listed or inherent to such process, method, article, or apparatus. Reference in this application to "connected," "coupled," and the like is not intended to be limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Reference to "a plurality" in this application means two or more. "and/or" describes an association relationship of associated objects, meaning that three relationships may exist, for example, "A and/or B" may mean: a exists alone, A and B exist simultaneously, and B exists alone. In general, the character "/" indicates a relationship in which the objects associated before and after are an "or". Reference in the present application to the terms "first," "second," "third," etc., merely distinguish between similar objects and do not denote a particular order or importance to the objects.
The method embodiments provided in the present embodiment may be executed in a terminal, a computer, or a similar computing device. For example, the method operates on a terminal, and fig. 1 is a block diagram of a hardware structure of the terminal of the network card connectivity detection method provided in the embodiment of the present application. As shown in fig. 1, the terminal may include one or more processors 102 (only one is shown in fig. 1) and a memory 104 for storing data, wherein the processors 102 may include, but are not limited to, a processing device such as a Microprocessor (MCU) or a Programmable logic device (FPGA). The terminal may also include a transmission device 106 for communication functions and an input-output device 108. It will be understood by those of ordinary skill in the art that the structure shown in fig. 1 is merely an illustration and is not intended to limit the structure of the terminal described above. For example, the terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be used to store a computer program, for example, a software program and a module of application software, such as a computer program corresponding to the network card connectivity detection method in the present embodiment, and the processor 102 executes the computer program stored in the memory 104 to execute various functional applications and data processing, i.e., implement the method described above. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some embodiments, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used to receive or transmit data via a network. The network described above includes a wireless network provided by a communication provider of the terminal. In one embodiment, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one embodiment, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
In this embodiment, a method for detecting network card connectivity is provided, and fig. 2 is a flowchart of the method for detecting network card connectivity provided in the embodiment of the present application, where an execution main body of the method may be an electronic device, and optionally, the electronic device may be a server or a terminal device, but the present application is not limited thereto. Specifically, as shown in fig. 2, the process includes the following steps:
step S201, determining a gateway MAC address of the network card to be tested and an IP address of a target server.
Exemplarily, a network card to be tested in the terminal device is determined, a Media Access Control Address (MAC), that is, an MAC Address, of the network card to be tested is determined based on the network card to be tested, and an Internet Protocol Address (IP), that is, an IP Address, of the target server is obtained.
Specifically, the terminal device may include multiple network cards such as an ethernet, a wireless network (wifi), a fourth generation mobile communication (4G), and the like, in order to save overhead, the ethernet is usually set as a default network card, and then other network cards such as wifi and 4G may be standby network cards, and the network card to be tested may be any one of the standby network cards.
It should be noted that the overhead in the embodiment of the present application may refer to performance overhead or cost overhead, and generally, a network card with one access mode with lower overhead among multiple network card access modes is determined as a default network card. When the default network card fails, the terminal device needs to switch to another network card to ensure the continuation of the service. When the default network card is recovered, the terminal device needs to switch back to the default network card to reduce the overhead of the whole service. That is, if the terminal device communicates with the target server through the standby network card currently, the network card to be tested may be the default network card. The network card to be tested can be set according to actual requirements, and is not limited herein. In the embodiment of the present application, only three network cards, that is, an ethernet card, a wifi card, and a 4G card, may be included in the terminal device, and in practical application, the terminal device may further include a network card for fifth-generation mobile communication (5G), a network card for third-generation mobile communication (3G), and the like, which is not limited herein.
It should be noted that the target server may refer to a public network server, that is, a server of a remote network connecting computers of local area networks or metropolitan area networks in different regions for communication.
Step S202, a test request is generated based on the gateway MAC address and the IP address of the target server.
Illustratively, the test request may be a data packet, where the data packet at least includes a destination MAC and a field corresponding to a destination IP, and may create an original socket, directly write the determined gateway MAC address into the field corresponding to the destination MAC in an encoding manner, and write the destination server IP address into the field corresponding to the destination IP, thereby generating the test request of the network card to be tested.
Step S203, sending the test request to the gateway of the network card to be tested through the socket, so that the gateway of the network card to be tested forwards the test request to the target server.
Further, the test request of the network card to be tested is sent to the gateway of the network card to be tested through the original socket, so that the gateway of the network card to be tested sends the test request to the target server. Therefore, when the connectivity test of the network card is carried out, the network card to be tested does not need to be selected by a route, even if the connectivity test of the network card to be tested is carried out in the process of carrying out service communication between the default network card and the target server, the default network card does not need to be disconnected by the route and is switched to the network card to be tested, and the normal communication of the current service is ensured.
And step S204, receiving feedback information forwarded by the gateway of the network card to be tested, and determining the connectivity of the network card to be tested and the target server based on the feedback information.
Wherein the feedback information may be generated by the target server based on the test request.
Specifically, after receiving the test request, the target server generates feedback information according to the test request, and forwards the feedback information to the network card to be tested through the gateway of the network card to be tested, so that the network card to be tested receives the feedback information.
Further, the electronic device acquires feedback information received by the network card to be tested, and determines connectivity between the network card to be tested and the target server according to the feedback information.
In the implementation process, a test request is directly generated according to the MAC address of the network card to be tested and the IP address of the target server, and further, the test request is sent to the gateway of the network card to be tested through the socket, so that the gateway of the network card to be tested forwards the test request to the target server, the gateway of the network card to be tested does not need to be selected through a route, namely, the gateway of the current service network card cannot be interrupted due to the connectivity test of the network card to be tested in the process of service communication between the terminal device and the server, the connectivity detection of the network card is realized in the service communication process, and the normal communication of the service is ensured. And the connectivity between the network card to be tested and the target server can be further conveniently determined according to the feedback information of the target server, so that a connectivity detection result can be obtained.
In some embodiments, determining the gateway MAC address of the network card to be tested may include the following steps:
step 1: and determining the gateway IP address of the network card to be tested.
And 2, step: a gateway MAC address is determined based on the gateway IP address.
Illustratively, there is a corresponding gateway for each network card, the gateway IP address is a "gateway" of one network to other networks, and is mainly used for data transmission between different networks, and the gateway MAC address, i.e. a physical address, is used to define the location of a network device.
The IP address of the corresponding gateway can be determined according to the network card to be tested, and further, the MAC address of the gateway can be determined according to the IP address of the gateway.
In the implementation process, the gateway MAC address is determined according to the gateway IP address of the network card to be tested, so that the test request can be further generated according to the gateway MAC address.
In some of these embodiments, determining the gateway MAC address based on the gateway IP address comprises:
the gateway MAC address is determined based on an address resolution protocol and the gateway IP address.
Illustratively, the Protocol stack determines a gateway MAC Address corresponding to the gateway IP Address through Address Resolution Protocol (ARP).
In the implementation process, the gateway MAC address corresponding to the gateway IP address is determined according to the address resolution protocol, so that the determination of the gateway MAC address is realized.
In some embodiments, generating the test request based on the gateway MAC address and the target server IP address may include:
step 1: and creating a socket based on the network protocol type of the network card to be tested.
And 2, step: and carrying out configuration operation on the socket to obtain a target socket, wherein the configuration operation comprises the binding of the socket and the network card to be tested and the configuration of the socket without routing selection.
And step 3: and binding the IP address of the target server and the MAC address of the gateway into a preset address resolution protocol to obtain the bound address resolution protocol.
And 4, step 4: and generating a test request based on the bound address resolution protocol and the target socket.
Illustratively, the network Protocol of the network card to be tested may have multiple types, for example, an Internet Control Message Protocol (ICMP), a Transmission Control Protocol (TCP), and a User Datagram Protocol (UDP), determine the network Protocol type of the network card to be tested, and further, create a corresponding socket according to the network Protocol type of the network card to be tested.
Specifically, if the network protocol type is ICMP protocol, a socket of an Internet Packet explorer (Packet Internet Groper, PING) may be created, that is, a PING socket is created; if the network protocol type is a TCP protocol, a TCP socket can be created; if the network protocol type is UDP, a UDP socket can be created.
Further, the created socket is configured to obtain a target socket, where the configuration operation may include binding the socket with the network card to be tested, and configuring the socket without routing. Specifically, the created socket can be bound with the network card to be tested through the SO _ bidi socket option, SO that in the network card connectivity detection process, a subsequently generated test request can be conveniently sent through a gateway corresponding to the network card to be tested, and the socket can be set to be not subjected to routing through the SO _ DONTROUTE socket option, SO that the gateway of the network card to be tested does not need to be determined through a routing mode, and normal interaction of current services can be effectively ensured.
Further, the IP address of the target server and the MAC address of the gateway are bound to a preset address resolution protocol to obtain the bound address resolution protocol. Specifically, the preset address resolution protocol may be a static ARP table, and the target server IP address and the gateway MAC address are bound to the static ARP table, so that in the process of generating the test request, the gateway MAC address does not need to be determined in the wide area network through routing, and the gateway MAC address of the network card to be tested can be directly obtained through the static ARP table, so that the obtained gateway MAC address can be written into a field corresponding to the destination MAC.
Further, generating a test request through the bound address resolution protocol and the target socket, specifically, if the created socket is a PING socket, the generated test request may be a request packet; if the created socket is a TCP socket, the generated test request can be a sync packet; if the created socket is a UDP socket, the generation yes test request may be a UDP packet. The gateway MAC address and the target server IP address are directly written into the corresponding field of the test request through the target socket, so that the test request is not generated in a mode of encoding the original socket, the encoding operation in the test request generation process is simplified, and the test request generation efficiency is further improved.
In the implementation process, the created socket is bound with the network card to be tested in a socket option mode, so that the test request is forwarded through the gateway of the network card to be tested, the created socket is set to be forbidden to select the route through the socket option, the network card to be tested can also be forwarded through the gateway of the network card to be tested without selecting the route in the connectivity detection process of the network card to be tested, in addition, the IP address of the target server and the MAC address of the gateway are bound into a preset address resolution protocol, the IP address of the target server and the MAC address of the gateway can be directly written into the corresponding field of the test request in the subsequent test request generation process, the coding operation in the test request generation process is simplified, and further, the test request generation efficiency is improved.
In some embodiments, sending the test request to the gateway of the network card to be tested through the socket includes: and sending the test request to the gateway of the network card to be tested through the target socket.
Further, the generated test request is sent to the gateway of the network card to be tested through the target socket, so that the operation of routing the network card to be tested is not needed in the network card connectivity detection process, and the normal communication of the current service is ensured.
In some embodiments, receiving feedback information forwarded by a gateway of the network card to be tested, and determining connectivity between the network card to be tested and the target server based on the feedback information may include the following steps:
step 1: if the feedback information forwarded by the gateway of the network card to be tested is received within the preset time, the connectivity of the network card to be tested and the target server is normal.
Step 2: and if the feedback information forwarded by the gateway of the network card to be tested is not received within the preset time, the connectivity of the network card to be tested and the target server is abnormal.
Illustratively, if the feedback message forwarded by the gateway of the network card to be tested is received within the preset time, it may be determined that the connectivity between the network card to be tested and the target server is normal, and if the feedback message forwarded by the gateway of the network card to be tested is not received within the preset time, it indicates that the connectivity between the network card to be tested and the target server is abnormal.
It should be noted that the preset time in the embodiment of the present application may be 1 second, or 2 seconds, or other times, and the preset time may be adaptively set, which is not limited herein.
In the implementation process, whether the connectivity of the network card to be tested is normal is determined according to whether the feedback information forwarded by the gateway of the network card to be tested is received within the preset time, and the detection result of the connectivity of the network card to be tested can be accurately determined.
In some embodiments, after determining connectivity between the network card to be tested and the target server based on the feedback information, the method further includes: and if the connectivity between the network card to be tested and the target server is abnormal, outputting an abnormal prompt.
Exemplarily, after determining connectivity of the network card to be tested, the method may further include: and when the connectivity of the network card to be tested and the target server is abnormal, generating abnormal prompt information, thereby facilitating the repair of the network card with abnormal connectivity.
In the implementation process, when the connectivity between the network card to be tested and the target server is abnormal, the abnormal prompt information is generated, so that the abnormal network card can be repaired conveniently.
The present embodiment is described and illustrated below by means of preferred embodiments.
Fig. 3 is a flowchart of another method for detecting network card connectivity according to an embodiment of the present disclosure, and as shown in fig. 3, the method for detecting network card connectivity includes the following steps:
step 301, determining the gateway IP address of the network card to be tested.
Specifically, the network card to be tested is determined, and the gateway IP address of the network card to be tested is determined according to the network card to be tested.
Step 302, determining the gateway MAC address of the network card to be tested according to the address resolution protocol.
Further, according to the ARP protocol, a gateway MAC address corresponding to the gateway IP address is obtained, so that the gateway MAC address of the network card to be tested is obtained.
Step 303, detecting the network protocol type of the network card to be detected.
Further, the network protocol type of the network card to be tested is detected, and a corresponding socket is created according to the network protocol type of the network card to be tested. Specifically, the network protocol type may include an ICMP protocol, a TCP protocol, and a UDP protocol, if the network protocol type of the network card to be tested is the UDP protocol, step 3041 is executed, if the network protocol type of the network card to be tested is the TCP protocol, step 3042 is executed, and if the network protocol type of the network card to be tested is the ICMP protocol, step 3043 is executed.
Step 3041: a UDP socket is created.
Specifically, if the network protocol type of the network card to be tested is the UDP protocol, a UDP socket is created.
Step 3042: a TCP socket is created.
And if the protocol type of the network card to be tested is the TCP protocol, creating a TCP socket.
Step 3043: a PING socket is created.
And if the protocol type of the network card to be tested is the ICMP, creating a PING socket.
And 305, binding the socket with the network card to be tested according to SO _ BINDTODEVICE.
Further, the created socket is bound with the network card to be tested through the SO _ bidi device socket option interface, SO that the test request is forwarded from the gateway of the network card to be tested.
And step 306, setting the socket to be not subjected to routing according to SO _ DONTROUTE.
Further, the created socket is set to be not subjected to routing selection through the SO _ DONTROUTE socket option interface, SO that the routing selection of the gateway of the network card to be tested is forbidden, the routing is not needed to switch the default network card to the network card to be tested, and the normal interaction of services is ensured.
Step 307, the target server IP address and the gateway MAC address are bound into a static ARP table.
And further, binding the IP address of the target server and the MAC address of the gateway into a static ARP table, and further generating a corresponding test request according to the bound static ARP table and the socket. Fig. 4 is a schematic structural diagram of a test request data packet provided in an embodiment of the present application, and as shown in fig. 4, the test request data packet may include: the network interface test method comprises the steps that a target MAC, a source IP, a target IP and other data are set, a gateway MAC address of a network card to be tested is directly written into a field corresponding to the target MAC through a set socket, an IP address of a target server is written into a field corresponding to the target IP, a data packet of the network card to be tested is generated, and a corresponding test request is further generated according to the data packet.
And 308, sending the test request data packet to a gateway of the network card to be tested.
Further, the generated test request is sent to the gateway of the network card to be tested through the configured socket, so that the gateway of the network card to be tested forwards the test request to the target server.
Step 309, determining whether feedback information is received within a preset time.
Specifically, after the target server receives the test request, feedback information is generated according to the test request, and the feedback information is forwarded to the network card to be tested through the gateway of the network card to be tested. Further, whether the network card to be tested receives the feedback information is judged within a preset time, if the network card to be tested receives the feedback information within the preset time, step 310 is executed, and if the network card to be tested does not receive the feedback information within the preset time, step 311 is executed.
At step 310, connectivity is normal.
If the network card to be tested receives the feedback information within the preset time, the connectivity between the network card to be tested and the target server is normal, and step 312 is executed.
Step 311, connectivity is abnormal.
If the network card to be tested does not receive the feedback information within the preset time, connectivity between the network card to be tested and the target server is abnormal, and step 312 is executed.
And step 312, ending.
Specifically, after determining the connectivity of the network card to be tested, the process is ended.
It should be noted that the steps illustrated in the above-described flow diagrams or in the flow diagrams of the figures may be performed in a computer system, such as a set of computer-executable instructions, and that, although a logical order is illustrated in the flow diagrams, in some cases, the steps illustrated or described may be performed in an order different than here.
In this embodiment, a device for detecting connectivity of a network card is also provided, and the device is used to implement the foregoing embodiments and preferred embodiments, and the description of the device that has been already made is omitted. The terms "module," "unit," "sub-unit," and the like as used below may implement a combination of software and/or hardware of predetermined functions. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 5 is a block diagram of a structure of a device for detecting connectivity of a network card according to an embodiment of the present application, and as shown in fig. 5, the device includes:
the determining module 501 is configured to determine a gateway MAC address of the network card to be tested and an IP address of the target server.
A generating module 502, configured to generate a test request based on the gateway MAC address and the target server IP address.
The sending module 503 is configured to send the test request to the gateway of the network card to be tested through the socket, so that the gateway of the network card to be tested forwards the test request to the target server.
And a connectivity detection module 504, configured to receive feedback information forwarded by a gateway of the network card to be tested, and determine connectivity between the network card to be tested and the target server based on the feedback information, where the feedback information is generated by the target server based on the test request.
In some embodiments, the determining module 501 is specifically configured to:
and determining the gateway IP address of the network card to be tested.
A gateway MAC address is determined based on the gateway IP address.
In some embodiments, the determining module 501 is specifically configured to:
the gateway MAC address is determined based on an address resolution protocol and the gateway IP address.
In some embodiments, the generating module 502 is specifically configured to:
and creating a socket based on the network protocol type of the network card to be tested.
And carrying out configuration operation on the socket to obtain a target socket, wherein the configuration operation comprises binding the socket with the network card to be tested and configuring the socket not to pass through routing selection.
And binding the IP address of the target server and the MAC address of the gateway into a preset address resolution protocol to obtain the bound address resolution protocol.
And generating a test request based on the bound address resolution protocol and the target socket.
In some embodiments, the sending module 503 is specifically configured to:
and sending the test request to the gateway of the network card to be tested through the target socket.
In some embodiments, the connectivity detection module 504 is specifically configured to:
if the feedback information forwarded by the gateway is received within the preset time, the connectivity between the network card to be tested and the target server is normal;
if the feedback information forwarded by the gateway is not received within the preset time, the connectivity between the network card to be tested and the target server is abnormal.
In some of these embodiments, the connectivity detection module 504 is further configured to:
and if the connectivity of the network card to be tested and the target server is abnormal, outputting an abnormal prompt.
It should be noted that the above modules may be functional modules or program modules, and may be implemented by software or hardware. For a module implemented by hardware, the above modules may be located in the same processor; or the modules can be respectively positioned in different processors in any combination.
There is also provided in this embodiment an electronic device comprising a memory having a computer program stored therein and a processor configured to execute the computer program to perform the steps of any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, determining a gateway MAC address of a network card to be tested and an IP address of a target server.
And S2, generating a test request based on the gateway MAC address and the IP address of the target server.
And S3, sending the test request to the gateway of the network card to be tested through the socket so that the gateway of the network card to be tested forwards the test request to the target server.
And S4, receiving feedback information forwarded by the gateway of the network card to be tested, and determining the connectivity of the network card to be tested and the target server based on the feedback information, wherein the feedback information is generated by the target server based on the test request.
It should be noted that, for specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and optional implementations, and details are not described again in this embodiment.
In addition, in combination with the method for detecting connectivity of a network card provided in the foregoing embodiment, a storage medium may also be provided in this embodiment. The storage medium has a computer program stored thereon; when executed by a processor, the computer program implements any one of the network card connectivity detection methods in the embodiments.
It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to be limiting. All other embodiments, which can be derived by a person skilled in the art from the examples provided herein without inventive step, shall fall within the scope of protection of the present application.
It is obvious that the drawings are only examples or embodiments of the present application, and it is obvious to those skilled in the art that the present application can be applied to other similar cases according to the drawings without creative efforts. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
The term "embodiment" is used herein to mean that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is to be expressly and implicitly understood by one of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the patent protection. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, and these are all within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims (9)

1. A method for detecting connectivity of a network card is characterized by comprising the following steps:
determining a gateway MAC address of a network card to be tested and an IP address of a target server;
generating a test request based on the gateway MAC address and the target server IP address;
wherein the generating a test request based on the gateway MAC address and the target server IP address comprises:
creating a socket based on the network protocol type of the network card to be tested; performing configuration operation on the socket to obtain a target socket, wherein the configuration operation comprises binding the socket with the network card to be tested and configuring the socket without routing; binding the IP address of the target server and the MAC address of the gateway into a preset address resolution protocol to obtain a bound address resolution protocol; generating the test request based on the bound address resolution protocol and the target socket;
sending the test request to the gateway of the network card to be tested through a socket so that the gateway of the network card to be tested forwards the test request to the target server;
and receiving feedback information forwarded by the gateway of the network card to be tested, and determining connectivity of the network card to be tested and the target server based on the feedback information, wherein the feedback information is generated by the target server based on the test request.
2. The method according to claim 1, wherein the determining the gateway MAC address of the network card to be tested comprises:
determining a gateway IP address of the network card to be tested;
determining the gateway MAC address based on the gateway IP address.
3. The method of claim 2, wherein the determining the gateway MAC address based on the gateway IP address comprises:
determining the gateway MAC address based on an address resolution protocol and the gateway IP address.
4. The method according to claim 1, wherein the sending the test request to the gateway of the network card to be tested through a socket comprises:
and sending the test request to the gateway of the network card to be tested through the target socket.
5. The method according to claim 1, wherein the receiving feedback information forwarded by the gateway of the network card to be tested and determining connectivity between the network card to be tested and the target server based on the feedback information comprises:
if the feedback information forwarded by the gateway is received within the preset time, the connectivity between the network card to be tested and the target server is normal;
and if the feedback information forwarded by the gateway is not received within the preset time, the connectivity between the network card to be tested and the target server is abnormal.
6. The method according to claim 5, wherein after determining connectivity between the network card to be tested and the target server based on the feedback information, further comprising:
and if the connectivity of the network card to be tested and the target server is abnormal, outputting an abnormal prompt.
7. A network card connectivity detection device, comprising:
the determining module is used for determining the gateway MAC address of the network card to be tested and the IP address of the target server;
a generation module for generating a test request based on the gateway MAC address and the target server IP address;
wherein the generation module is specifically configured to: creating a socket based on the network protocol type of the network card to be tested; performing configuration operation on the socket to obtain a target socket, wherein the configuration operation comprises binding the socket with the network card to be tested and configuring the socket not to pass through routing selection; binding the IP address of the target server and the MAC address of the gateway into a preset address resolution protocol to obtain a bound address resolution protocol; generating the test request based on the bound address resolution protocol and the target socket;
the sending module is used for sending the test request to the gateway of the network card to be tested through a socket so that the gateway of the network card to be tested forwards the test request to the target server;
and the connectivity detection module is used for receiving feedback information forwarded by the gateway of the network card to be tested and determining the connectivity between the network card to be tested and the target server based on the feedback information, wherein the feedback information is generated by the target server based on the test request.
8. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the computer program to perform the network card connectivity detection method of any one of claims 1 to 6.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the network card connectivity detection method according to any one of claims 1 to 6.
CN202211219332.XA 2022-10-08 2022-10-08 Network card connectivity detection method and device, electronic device and storage medium Active CN115297028B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211219332.XA CN115297028B (en) 2022-10-08 2022-10-08 Network card connectivity detection method and device, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211219332.XA CN115297028B (en) 2022-10-08 2022-10-08 Network card connectivity detection method and device, electronic device and storage medium

Publications (2)

Publication Number Publication Date
CN115297028A CN115297028A (en) 2022-11-04
CN115297028B true CN115297028B (en) 2023-01-03

Family

ID=83834821

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211219332.XA Active CN115297028B (en) 2022-10-08 2022-10-08 Network card connectivity detection method and device, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN115297028B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113872826A (en) * 2021-08-31 2021-12-31 苏州浪潮智能科技有限公司 Network card port stability testing method, system, terminal and storage medium
CN115022215A (en) * 2022-05-25 2022-09-06 四川九州电子科技股份有限公司 Method and system for testing MAC address of optical network unit

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100414936C (en) * 2006-06-30 2008-08-27 中国科学院计算技术研究所 Method for balancing load between multi network cards of network file system server
CN102064964B (en) * 2010-12-13 2012-09-05 中国人民解放军国防科学技术大学 Method for rapidly switching gigabit network cards in gigabit switching environment
US20160127152A1 (en) * 2011-09-26 2016-05-05 Theranos, Inc. Network connectivity methods and systems
CN106549912B (en) * 2015-09-17 2019-03-12 视联动力信息技术股份有限公司 A kind of playback method and system of video data
CN110572275B (en) * 2019-08-01 2022-09-09 新华三技术有限公司成都分公司 Network card switching method and device, server and computer readable storage medium
EP3860035A1 (en) * 2020-01-29 2021-08-04 Sebastien Armleder Storing and determining a data element
CN115086208A (en) * 2022-06-14 2022-09-20 深信服科技股份有限公司 Network card detection method and device, electronic equipment and storage medium

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113872826A (en) * 2021-08-31 2021-12-31 苏州浪潮智能科技有限公司 Network card port stability testing method, system, terminal and storage medium
CN115022215A (en) * 2022-05-25 2022-09-06 四川九州电子科技股份有限公司 Method and system for testing MAC address of optical network unit

Also Published As

Publication number Publication date
CN115297028A (en) 2022-11-04

Similar Documents

Publication Publication Date Title
US9219641B2 (en) Performing failover in a redundancy group
CN104469789A (en) Connection configuration method and system for intelligent household appliance
CN110191066B (en) Method, equipment and system for determining maximum transmission unit (PMTU)
US11178032B2 (en) Connectivity monitoring for data tunneling between network device and application server
JP7430224B2 (en) Packet processing methods and gateway devices
CN102315969A (en) Neighbor discovery protocol graceful restart (GR) processing method and device
US11140597B2 (en) Method and apparatus for processing link establishment failure, and computer storage medium
CN113794618B (en) Redundant network communication method and device based on virtual network card and terminal equipment
JP5039975B2 (en) Gateway device
CN109818901B (en) Method, device and system for determining message header compression mechanism
CN111935108B (en) Cloud data security access control method and device, electronic device and storage medium
CN115297028B (en) Network card connectivity detection method and device, electronic device and storage medium
CN116233279A (en) Message processing method, device and system
CN107948002B (en) AP access control method and device
WO2022007861A1 (en) Failure notification method and electronic device
CN107666671B (en) Method and device for detecting wrong connection based on TWAMP
US11363103B2 (en) Dynamic user plane function (UPF) selection based on supported protocol type
CN114024903A (en) Network switching method and device and gateway equipment
CN114390454A (en) Message transmission method, system, electronic device and storage medium
CN112235840A (en) Session terminal switching method, device, entity and system
WO2002052426A9 (en) Network availability
US10404652B2 (en) Communication device, communication method, and program
CN113784379B (en) Network management method and device
CN108337147B (en) Message forwarding method and device
CN116261225A (en) Capacity adjustment method, device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant