Summary of the invention
The shortcoming of prior art in view of the above, the object of the present invention is to provide and a kind ofly detect Interface status and according to the method and system of Interface status Processing Interface fault, be used for solving prior art communication terminal device, particularly router is in the situation that connecting LAN interface and wan interface, cannot automatically detect wan interface connection status and know as early as possible network failure, and communication terminal device in same network segment situation, cannot solve the problem that client cannot connecting Internet at LAN interface and wan interface.
For achieving the above object and other relevant objects, one aspect of the present invention provides a kind of and detects Interface status and according to the method for Interface status Processing Interface fault, be applied to there is first interface, the communication terminal device of the second interface, a plurality of network interface cards, network parameter is configured on described communication terminal device, comprise: step 1 creates a Virtual File System when starting described communication terminal device; Step 2, pre-defined one in order to reconfigure the signal process function of network parameter at described first interface and the second interface during in the same network segment and in order to create the socket function of web socket; Step 3, controls request to obtain title and the first interface state return value of described network interface card by the input and output of described web socket association, and from described Virtual File System, obtains network interface card information; Step 4, according to the network interface card information getting and the title of network interface card, whether the network interface card information that judgement is obtained mates with described network interface card; Step 5, if the network interface card information of obtaining is mated with described network interface card, according to described first interface state return value, judge that whether described first interface is in connection status, if not, send alarm and occur that with first interface described in prompting user interface fault makes user process described interface fault; If so, continue to carry out next step; Whether step 6, detect described first interface and the second interface in the same network segment; If described first interface and the second interface in the same network segment, call described signal process function with reconfigure described communication terminal device network parameter so that described first interface and the second interface not in the same network segment.
Alternatively, described network parameter comprises IP address value and the gateway address value of IP address value and gateway address value and second interface of first interface.
Whether in the same network segment further comprise: IP address value and the gateway address value of obtaining IP address value and gateway address value and second interface of first interface if alternatively, in described step 6, detecting described first interface and the second interface; Respectively the IP address value of described first interface and gateway address value are carried out to logical operation, the IP address value of described the second interface and gateway address value are carried out logical operation to obtain the network segment of first interface and the network segment of the second interface; According to the network segment of the network segment of the first interface getting and the second interface, whether detect described first interface and described the second interface in the same network segment.
Alternatively, described logical operation refers to logical AND operation.
Alternatively, described detection Interface status and according to the method for Interface status Processing Interface fault after reconfiguring the network parameter of described communication terminal device, also comprise: preserve the network parameter reconfiguring, send the enabled instruction of restarting described communication terminal device.
Alternatively, when described first interface state return value is 0x0, represent that described first interface is in off-state; When described first interface state return value is 0x10, represent that described first interface is in connection status.
Alternatively, in described step 5, carry out and send alarm and for described first interface, occur that interface fault makes user process after described interface fault with prompting, enter wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface; In described step 6, carry out call described signal process function with reconfigure described communication terminal device network parameter so that described first interface and the second interface not after the same network segment, enter wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface, return to afterwards step 1.
The present invention also provides on the other hand a kind of and detects Interface status and according to the system of Interface status Processing Interface fault, be applied to there is first interface, the communication terminal device of the second interface and a plurality of network interface cards, network parameter is configured on described communication terminal device, comprise: initialization module, for creating a Virtual File System when starting described communication terminal device; Predefine module, for pre-defined one in order to reconfigure the signal process function of network parameter at described first interface and the second interface during in the same network segment and in order to create the socket function of web socket; Acquisition module, controls request to obtain title and the first interface state return value of described network interface card for the input and output by described web socket association, obtains network interface card information from described Virtual File System; The first judge module, for according to the network interface card information getting and the title of network interface card, judges whether the network interface card information of obtaining mates with described network interface card; The second judge module, while mating with described network interface card for the network interface card information of obtaining in described the first judge module judgement, according to described first interface state return value, judge that whether described first interface is in connection status, if not, call for sending alarm and occur that with first interface described in prompting user interface fault makes user process the alarm module of described interface fault; If so, whether call for detection of described first interface and the second interface the detection module in the same network segment; If described first interface and the second interface in the same network segment, call the signal process function of described predefine module definition reconfigure described communication terminal device network parameter so that described first interface and the second interface not in the same network segment.
Alternatively, in described alarm module execution, sending alarm occurs for described first interface calling a time block after interface fault makes user process described interface fault with prompting, described time block is used for arranging a default stand-by period section, make described communication terminal device in wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface; At described detection module, at call signal, process function and reconfigure described network parameter so that described first interface and the second interface do not call described time block after the same network segment yet, make described communication terminal device in wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface.
Alternatively, described detection module also comprises: acquiring unit, for obtaining IP address value and the gateway address value of IP address value and gateway address value and second interface of first interface; Logical operations unit, for respectively the IP address value of described first interface and gateway address value being carried out to logical operation, the IP address value of described the second interface and gateway address value are carried out logical operation to obtain the network segment of first interface and the network segment of the second interface.
As mentioned above, detection Interface status of the present invention according to the method and system of Interface status Processing Interface fault, there is following beneficial effect: detection Interface status of the present invention has also solved routing device side WAN mouth and LAN mouth in same network segment situation according to the method and system of Interface status Processing Interface fault, client cannot connect the problem of online, can be when WAN mouth connects disconnection, reminding user is plugged netting twine, prevent that user cannot connecting Internet, process better network failure, improved resource utilization ratio.
Embodiment
Below, by specific instantiation explanation embodiments of the present invention, those skilled in the art can understand other advantages of the present invention and effect easily by the disclosed content of this specification.The present invention can also be implemented or be applied by other different embodiment, and the every details in this specification also can be based on different viewpoints and application, carries out various modifications or change not deviating under spirit of the present invention.It should be noted that, in the situation that not conflicting, the feature in following examples and embodiment can combine mutually.
It should be noted that, the diagram providing in following examples only illustrates basic conception of the present invention in a schematic way, satisfy and only show with assembly relevant in the present invention in graphic but not component count, shape and size drafting while implementing according to reality, during its actual enforcement, kenel, quantity and the ratio of each assembly can be a kind of random change, and its assembly layout kenel also may be more complicated.
The present invention is directed to communication terminal device, particularly router, is connecting in LAN interface and wan interface situation, a kind of automatic detection Interface status situation is provided and has solved at both sides interface in same network segment situation, and client cannot connect the situation of online.When WAN mouth connects disconnection, reminding user is plugged netting twine.In WAN mouth and LAN interface, under the same network segment, address this problem, prevent that user cannot connecting Internet, process better network failure.Detection Interface status of the present invention does not also need finger daemon according to the method and system of Interface status Processing Interface fault, independently carries out, and has improved resource utilization ratio.
Embodiment mono-
The present embodiment provide a kind of detect Interface status and according to the method for Interface status Processing Interface fault, be applied to there is first interface, the communication terminal device of the second interface and a plurality of network interface cards, network parameter is configured on described communication terminal device.In the present embodiment, described communication terminal device is router, and described first interface is WAN (local area network (LAN)) interface, and the second interface is LAN (wide area network) interface.Refer to Fig. 1, be shown as and detect Interface status and according to the schematic flow sheet of the method for Interface status Processing Interface fault.As shown in Figure 1, described detection Interface status comprising according to the method for Interface status Processing Interface fault:
S1 creates a Virtual File System when starting described communication terminal device.Described Virtual File System is the PROC file system that will create in embedded Linux system start-up course.Described PROC file system is a pseudo-file system, and it only exists in the middle of internal memory, and does not take external space.It take the operation that the mode of file system is access system kernel data provides interface.User and application program can obtain by PROC the information of system, and can change some parameter of kernel.Due to the information of system, as process, be dynamically to change, so when user or application program read PROC file system, PROC file system is dynamically read information needed and submit to from system kernel.
S2, a pre-defined signal process function and socket function, described signal process function is in order to reconfigure the signal process function of network parameter during in the same network segment at described first interface and the second interface.Described socket function is in order to create web socket, i.e. UDP (User Datagram Protocol, User Datagram Protoco (UDP)) socket.Wherein, described signal process function is SIGUSRI signal process function, and described socket function is socket function.
S3, controls request to obtain title and the first interface state return value of described network interface card by the input and output of described web socket association; After described UDP socket creates, just can get the filec descriptor of described PROC file system, the described filec descriptor getting by use is used with the input and output of described UDP sockets associated and controls title and the wan interface state return value that request can get network interface card in described router.In the present embodiment, wan interface state return value is 0x0 or 0x10, wherein, when described first interface state return value is 0x0, represents that described first interface is in off-state.When described first interface state return value is 0x10, represent that described first interface is in connection status.In this step S3, also from described Virtual File System, from described PROC file system, obtain network interface card information.
S4, according to the network interface card information acquiring and the title of network interface card, whether the network interface card information that judgement is obtained mates with network interface card in described routing device; If the network interface card information getting is mated with network interface card in described routing device, continue execution step S5.If the network interface card information getting is not mated with network interface card in described routing device, return to step S1.
S5, if the network interface card information of obtaining is mated with described network interface card, according to described first interface state return value, judge that whether described first interface is in connection status, when if described first interface state return value is 0x0, represent that described first interface is in off-state, perform step S6, send alarm and occur that with first interface described in prompting user interface fault makes user process described interface fault, and proceed to step S10, enter wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface; When if described first interface state return value is 0x10, represent that described first interface is in connection status, continue to carry out next step S7.In the present embodiment, acquiescence the second interface 22, LAN mouth is in connection status.
Whether S7, during in connection status, continue to detect described first interface and described the second interface in the same network segment at described first interface; If described first interface and the second interface is not in the same network segment, proceed to step S10, enter wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface, after executing described step S10, return to step S1, the described default stand-by period can arrange by artificial; If described first interface and the second interface, in the same network segment, perform step S8.Refer to Fig. 2, be shown as the idiographic flow schematic diagram of step S7, step S7 comprises the following steps:
S71, obtains the gateway address value of IP address value and the described first interface of described first interface and the IP address value of described the second interface and the gateway address value of the second interface.
S72, respectively the gateway address value of the IP address value of described first interface and described first interface is carried out to logical AND operation, the IP address value of described the second interface and the gateway address value of the second interface are carried out logical AND operation to obtain the network segment of first interface and the network segment of the second interface.
Whether S73, detect described first interface and described the second interface in the same network segment according to the network segment of the network segment of the first interface getting and the second interface, if so, performs step S8, if not, proceeds to step S10.
S8, call described signal process function with reconfigure described routing device network parameter so that described first interface and the second interface not in the same network segment.
S9, after reconfiguring the network parameter of described routing device, the network parameter that preservation reconfigures, send the enabled instruction of restarting described routing device, return to step S1, circulation is carried out described detection Interface status and according to the method for Interface status Processing Interface fault, until close described routing device.
In the present embodiment, unless close routing device, otherwise described detection Interface status process always and detect first interface connection status according to the method for Interface status Processing Interface fault.
Detection Interface status described in the present embodiment has also solved routing device side WAN mouth and LAN mouth in same network segment situation according to the method for Interface status Processing Interface fault, client cannot connect the problem of online, and can be when WAN mouth connects disconnection, reminding user is plugged netting twine, prevent that user cannot connecting Internet, process better network failure, improved resource utilization ratio.
Embodiment bis-
The present embodiment provide a kind of detect Interface status and according to the system 10 of Interface status Processing Interface fault, be applied to there is first interface, the communication terminal device of the second interface, a plurality of network interface cards, network parameter is configured on described communication terminal device.In the present embodiment, described communication terminal device is router two, and described first interface 21 is WAN (local area network (LAN)) interface, and the second interface 22 is LAN (wide area network) interface.Refer to Fig. 3, be shown as and detect Interface status and according to the theory structure schematic diagram of the system of Interface status Processing Interface fault.As shown in Figure 2, described detection Interface status comprising according to the system 10 of Interface status Processing Interface fault: initialization module 101, predefine module 102, acquisition module 103, the first judge module 104, the second judge module 105, alarm module 106, detection module 107, time block 108, memory module 109, the module 100 that starts.Wherein, described detection module 107 comprises acquiring unit 1071, logical operations unit 1072 and detecting unit 1073.
Described initialization module 101 for creating a Virtual File System when starting described routing device 2.Described Virtual File System is the PROC file system that will create in embedded Linux system start-up course.
The described predefine module 102 being connected with described initialization module 101 for pre-defined one in order to reconfigure the signal process function of network parameter at described first interface 21 and the second interface 22 during in the same network segment and in order to create the socket function of web socket.Wherein, described signal process function is SIGUSRI signal process function, and described socket function is socket function, i.e. UDP (User Datagram Protocol, User Datagram Protoco (UDP)) socket.
The acquisition module 103 connecting with described predefine module 102 is for controlling request to obtain title and the first interface state return value of described network interface card by the associated input and output of described web socket, and obtains network interface card information from described PROC file system;
Described the first judge module 104 being connected with described acquisition module 103 is for judging according to the network interface card information acquiring and the title of network interface card whether obtained network interface card information mates with described network interface card.That is to say if described network interface card information is corresponding with the network interface card in routing device 2, just illustrate that both mate.
The second judge module 105 being connected with described the first judge module 104 judges that according to described first interface state return value whether described first interface 21 is in connection status while mating with described network interface card for the network interface card information of obtaining in described the first judge module judgement, if in off-state, calling for sending alarm, described first interface 21 occurs that with first interface 21 described in prompting user interface fault makes user process the alarm module 106 of described interface fault; If whether described first interface 21 in connection status, calls for detection of described first interface 21 and the second interface 22 detection module 107 in the same network segment; If described first interface 21 and the second interface 22 in the same network segment, call the signal process function of described predefine module 102 definition reconfigure described routing device 2 network parameter so that described first interface 21 and the second interface 22 not in the same network segment.If first interface 21 and the second interface 22 are when the same network segment, so first interface 21 namely WAN mouth cannot obtain IP address, user also just cannot be connected to the Internet so, so still need call signal to process the network parameter that function reconfigures routing device 2.
106 execution of described alarm mould are sent alarm and are occurred can calling a time block 109 being connected with described alarm module 106 after interface fault makes user process described interface fault for described first interface 21 with prompting, described time block 109 is for arranging a default stand-by period section, make described routing device 2 in wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface 21.
Refer to Fig. 4, be shown as the theory structure schematic diagram of detection module, described detection module 107 comprises:
For obtaining the acquiring unit 1071 of the IP address value of first interface 21 and the gateway address value of first interface 21 and the IP address value of the second interface 22 and the gateway address value of the second interface.
For respectively the IP address value of described first interface 21 and first interface 21 gateway address values being carried out to logical operation, the gateway address value of the IP address value of described the second interface 22 and the second interface 22 is carried out logical AND operation to obtain the logical operations unit 1072 of the network segment of first interface 21 and the network segment of the second interface 22.And
For according to described logical operations unit 1072 logical operations to the network segment of first interface 21 and the network segment of the second interface 22 detect the whether detecting unit 1073 in the same network segment of described first interface 21 and the second interface 22.
At described detection module 107, described first interface 21 detected and the second interface 22 does not call described time block 109 after the same network segment yet, make described routing device in wait state, in default stand-by period section, wait for the connection status that continues to detect described first interface 21.Described detection module 107 detect signal process function that described first interface 21 and the second interface 22 calls described predefine module 102 definition after agreeing to the network segment reconfigure described routing device 2 network parameter so that described first interface 21 and the second interface 22 not in the same network segment, make described memory module 109 preserve the network parameter reconfiguring, send the enabled instruction of restarting described routing device 2 and make it restart described routing device 2 to starting module 100.In the present embodiment, described detection Interface status and according to the system 10 of Interface status Processing Interface fault always the state of connection status in detecting WAN mouth until close routing device 2.
Detection Interface status described in the present embodiment has also solved routing device side WAN mouth and LAN mouth in same network segment situation according to the method and system of Interface status Processing Interface fault, client cannot connect the problem of online, and can be when WAN mouth connects disconnection, reminding user is plugged netting twine, prevent that user cannot connecting Internet, process better network failure, improved resource utilization ratio.
So the present invention has effectively overcome various shortcoming of the prior art and tool high industrial utilization.
Above-described embodiment is illustrative principle of the present invention and effect thereof only, but not for limiting the present invention.Any person skilled in the art scholar all can, under spirit of the present invention and category, modify or change above-described embodiment.Therefore, such as in affiliated technical field, have and conventionally know that the knowledgeable, not departing from all equivalence modifications that complete under disclosed spirit and technological thought or changing, must be contained by claim of the present invention.