Detect Interface status and according to the method and system of Interface status Processing Interface failure
Technical field
The invention belongs to computer communication complex technical field, more particularly to a kind of detection Interface status and according to interface shape
The method and system of state Processing Interface failure.
Background technology
Router is a kind of computer network facility, provides routing and forwarding two kinds of important mechanisms, is connection LAN, wide
The equipment of domain net.Lan interfaces (LAN interface) are mainly used for router and LAN connection.Router is connected with wide area network
Interface is known as Wide Area Network interface (wan interface).Router is connected between LAN and wide area network, wide area network between LAN
Bridge.Router is connected by cable with interface, configures or obtain corresponding network address, could be given and is normally connected to interconnection
Net.The network equipment is connected by wan interface with first line of a couplet equipment, if cable is not inserted or network interface does not get up, network connects
Mouth is off.If the LAN interface of first line of a couplet equipment and router is in the same network segment, router LAN interface can not
Network address is obtained, wan interface status indicator lamp at this time no matter is to look at and is also to look at Interface status, router is all just
Often, but client can not obtain network address always, be not easy to network management personnel's discovery.
The whether normal method of detection router interface is network overhaul personnel most easy detection network interface state at present
Whether whether normal method is to look at interface lamp bright.If interface lamp is just always on, just it is not easy to find network device interface failure original
Cause, if the LAN interface and wan interface of router are in the same network segment, such case is not easy to find very much, and causes to route
Device can not obtain address always, and second line of a couplet client can not surf the Internet.Therefore, it is possible to detect Interface status automatically, and repair network
Failure can be in shorter time communication back to normal.
Therefore, a kind of detection Interface status how is provided and according to the method and system of Interface status Processing Interface failure, with
Communication terminal device of the prior art is solved, particularly router, can not in the case of connection LAN interface and wan interface
It is automatic to detect wan interface connection status and know network failure as early as possible, and communication terminal device is in LAN interface and wan interface
In the case of the same network segment, the defects of client can not connect internet can not be solved, it is real to have become practitioner in the art urgently
Technical problem to be solved.
The content of the invention
In view of the foregoing deficiencies of prior art, it is an object of the invention to provide a kind of detection Interface status and evidence to connect
The method and system of mouth state processing interface fault, for solving communication terminal device in the prior art, particularly router exists
In the case of connecting LAN interface and wan interface, wan interface connection status can not be detected automatically and know network failure as early as possible, and
And communication terminal device is in the same network segment in LAN interface and wan interface, can not solve client can not connect interconnection
The problem of net.
In order to achieve the above objects and other related objects, one aspect of the present invention provides a kind of detection Interface status and according to interface
The method of state processing interface fault, applied to first interface, second interface, multiple network interface cards communication terminal device, net
Network parameter configuration on the communication terminal device, including:It is virtual to create one when starting the communication terminal device for step 1
File system;Step 2 pre-defines one to be reconfigured when the first interface and second interface are in the same network segment
The signal process function of network parameter and the socket function to create web socket;Step 3 passes through the network set
The associated input and output control data of word is connect to obtain the title of the network interface card and first interface state return value and from the void
Intend obtaining network interface card information in file system;Step 4 according to the network interface card information and the title of network interface card got, judges acquired
Whether network interface card information matches with the network interface card;Step 5, if acquired network interface card information is matched with the network interface card, according to
Whether first interface state return value judges the first interface in connection status, if it is not, then sending alarm to prompt user
Interface fault, which occurs, in the first interface makes user handle the interface fault;If so, continue to execute next step;Step
Six, whether the first interface and second interface are detected in the same network segment;If the first interface and second interface are in same
One network segment then calls the signal process function to reconfigure the network parameter of the communication terminal device so that described
One interface and second interface are not at the same network segment.
Optionally, the IP address value of the network parameter including first interface and the IP of gateway address value and second interface
Location is worth and gateway address value.
Optionally, the first interface is detected in the step 6 and whether second interface further wraps in the same network segment
It includes:The IP address value and gateway address value and the IP address value of second interface and gateway address value of acquisition first interface;It is right respectively
The IP address value of the first interface and the progress logical operation of gateway address value, the IP address value of the second interface and gateway
Location value carries out logical operation to obtain the network segment of the network segment of first interface and second interface;According to the net of the first interface got
The network segment of section and second interface detects the first interface and whether the second interface is in the same network segment.
Optionally, the logical operation refers to that logical AND operates.
Optionally, it is described to detect Interface status and reconfiguring described lead to according to the method for Interface status Processing Interface failure
After the network parameter for believing terminal device, further include:The network parameter that reconfigures is preserved, is sent and is restarted the communication terminal and set
Standby enabled instruction.
Optionally, when the first interface state return value is 0x0, then it represents that the first interface is off;
When the first interface state return value is 0x10, then it represents that the first interface is in connection status.
Optionally, performed in the step 5 and send alarm to prompt interface fault order occur for the first interface
After user handles the interface fault, into wait state, wait continuing to detect described first in default waiting period and connect
The connection status of mouth;Being performed in the step 6 calls the signal process function to reconfigure the communication terminal device
Network parameter so that the first interface and second interface be not at the same network segment after, into wait state, default etc.
It treats to wait in the period and continues to detect the connection status of the first interface, afterwards return to step one.
Another aspect of the present invention also provides a kind of detection Interface status and according to the system of Interface status Processing Interface failure, should
For the communication terminal device with first interface, second interface and multiple network interface cards, network parameter configuration is whole in the communication
In end equipment, including:Initialization module, for creating a Virtual File System when starting the communication terminal device;In advance
Definition module, for pre-defining one reconfiguring network when the first interface and second interface are in the same network segment
The signal process function of parameter and the socket function to create web socket;Acquisition module, for passing through the network
The input and output control data of sockets associated is to obtain the title of the network interface card and first interface state return value, from the void
Intend obtaining network interface card information in file system;First judgment module, for according to the network interface card information and the title of network interface card got, sentencing
Whether acquired network interface card information of breaking matches with the network interface card;Second judgment module, for judging in first judgment module
Judge that the first interface is according to the first interface state return value when acquired network interface card information is matched with the network interface card
It is no to be in connection status, if it is not, then calling to send alarm so that first interface described in user to be prompted interface fault order use occur
Family handles the alarm module of the interface fault;If so, it calls to detect whether the first interface and second interface are located
In the detection module of the same network segment;If the first interface and second interface are in the same network segment, the predefined mould is called
The signal process function that block defines reconfigures the network parameter of the communication terminal device so that the first interface and
Two interfaces are not at the same network segment.
Optionally, alarm is sent in alarm module execution to prompt interface fault order occur for the first interface
User calls a timing module after handling the interface fault, and the timing module makes for setting a default waiting period
The communication terminal device is waited for, and is waited in default waiting period and is continued the connection for detecting the first interface
State;The detection module call signal processing function reconfigure the network parameter so that the first interface and
Second interface is not at also calling the timing module after the same network segment, and the communication terminal device is made to be waited for,
It is waited in default waiting period and continues to detect the connection status of the first interface.
Optionally, the detection module further includes:Acquiring unit, for obtaining the IP address value of first interface and gateway
Location is worth and the IP address value of second interface and gateway address value;Logical operations unit, for respectively to the IP of the first interface
Address value carries out logical operation with gateway address value, and the IP address value and gateway address value of the second interface carry out logical operation
To obtain the network segment of the network segment of first interface and second interface.
As described above, the present invention's detects Interface status and according to the method and system of Interface status Processing Interface failure, tool
There is following advantageous effect:It is of the present invention to detect Interface status and according to the method and system solution of Interface status Processing Interface failure
WAN mouthfuls of routing device side and LAN mouthfuls determined in the case that in the same network segment, client can not connect online the problem of, it can be with
When WAN mouthfuls of connections disconnect, user is reminded to plug cable, prevents user from can not connect internet, preferably handles network
Failure improves resource utilization ratio.
Description of the drawings
Fig. 1 is shown as the detection Interface status of the present invention and illustrates according to the method flow of Interface status Processing Interface failure
Figure.
Fig. 2 is shown as present invention detection Interface status and according to the tool of step S7 in the method for Interface status Processing Interface failure
Body flow diagram.
Fig. 3 is shown as present invention detection Interface status and according to the system principle structural representation of Interface status Processing Interface failure
Figure.
Fig. 4 is shown as present invention detection Interface status and according to detection module in the system of Interface status Processing Interface failure
Theory structure schematic diagram.
Component label instructions
10 detect Interface status and according to the system of Interface status Processing Interface failure
101 initialization modules
102 predefined modules
103 acquisition modules
104 first judgment modules
105 second judgment modules
106 alarm modules
107 detection modules
108 timing modules
109 memory modules
100 starting modules
1071 acquiring units
1072 logical operations units
1073 detection units
S1~S10 steps
Specific embodiment
Illustrate embodiments of the present invention below by way of specific specific example, those skilled in the art can be by this specification
Disclosed content understands other advantages and effect of the present invention easily.The present invention can also pass through in addition different specific realities
The mode of applying is embodied or practiced, the various details in this specification can also be based on different viewpoints with application, without departing from
Various modifications or alterations are carried out under the spirit of the present invention.It should be noted that in the case where there is no conflict, following embodiment and implementation
Feature in example can be mutually combined.
It should be noted that the diagram provided in following embodiment only illustrates the basic structure of the present invention in a schematic way
Think, then only the display component related with the present invention rather than component count, shape and size during according to actual implementation in schema
It draws, kenel, quantity and the ratio of each component can be a kind of random change during actual implementation, and its assembly layout kenel
It is likely more complexity.
The present invention, in connection LAN interface and wan interface, is provided for communication terminal device, particularly router
A kind of automatic detection Interface status situation simultaneously solves to be in the same network segment in both sides interface, and client can not connect
The situation of net.When WAN mouthfuls of connections disconnect, user is reminded to plug cable.At WAN mouthfuls the same network segment is in LAN interface
Under, it solves the problems, such as this, prevents user from can not connect internet, preferably handle network failure.Detection interface of the present invention
Simultaneously finger daemon is not required according to the method and system of Interface status Processing Interface failure in state, independent to carry out, and improves system money
Source utilization rate.
Embodiment one
The present embodiment provides a kind of detection Interface status and according to the method for Interface status Processing Interface failure, applied to
The communication terminal device of first interface, second interface and multiple network interface cards, network parameter are configured on the communication terminal device.
In the present embodiment, the communication terminal device be router, the first interface be WAN (LAN) interface, second interface
For LAN (wide area network) interface.Referring to Fig. 1, being shown as detection Interface status and according to the method for Interface status Processing Interface failure
Flow diagram.As shown in Figure 1, described detect Interface status and include according to the method for Interface status Processing Interface failure:
S1 creates a Virtual File System when starting the communication terminal device.The Virtual File System is insertion
The PROC file system that will be created in formula linux system start-up course.The PROC file system is a pseudo file system,
It is only existed among memory, and is not take up external space.It is the operation of access system kernel data in a manner of file system
Interface is provided.User and application program can obtain the information of system by PROC, and can change some parameters of kernel.By
It is that dynamic changes in the information of system, such as process, so when user or application program read PROC file system, PROC texts
Part system is that dynamic reads information needed from system kernel and submits.
S2 pre-defines a signal process function and socket function, and the signal process function is to described first
Interface and second interface reconfigure the signal process function of network parameter when being in the same network segment.The socket function to
Create web socket, i.e. UDP (User Datagram Protocol, User Datagram Protocol) socket.Wherein, the letter
Number processing function be SIGUSRI signal process functions, the socket function be socket functions.
S3, by the associated input and output control data of the web socket to obtain the title of the network interface card and first
Interface status return value;The filec descriptor of the PROC file system just can be got after UDP socket establishment,
It can be obtained by using the filec descriptor use got and the associated input and output control data of the UDP socket
The title of network interface card and wan interface state return value into the router.In the present embodiment, wan interface state return value is
0x0 or 0x10, wherein, when the first interface state return value is 0x0, represent that the first interface is off.
When the first interface state return value is 0x10, represent that the first interface is in connection status.In this step S3, also
From the Virtual File System, i.e., obtain network interface card information from the PROC file system.
S4, according to the network interface card information and the title of network interface card acquired, judge acquired network interface card information whether with the road
It is matched by network interface card in equipment;If the network interface card information got is matched with network interface card in the routing device, step S5 is continued to execute.
If the network interface card information got is mismatched with network interface card in the routing device, return to step S1.
S5 if acquired network interface card information is matched with the network interface card, judges according to the first interface state return value
Whether the first interface if the first interface state return value be 0x0, represents the first interface in connection status
It is off, then performs step S6, that is, send alarm and make user so that first interface described in user to be prompted interface fault occur
The interface fault is handled, and is transferred to step S10, i.e., into wait state, is waited in default waiting period and continues to detect
The connection status of the first interface;If the first interface state return value is 0x10, represent that the first interface is in
Connection status then continues to execute next step S7.In the present embodiment, second interface 22 is given tacit consent to, i.e. LAN mouthfuls is in connection shape
State.
S7, when the first interface is in connection status, continue to detect the first interface and the second interface be
It is no to be in the same network segment;If the first interface and second interface are not in the same network segment, step S10 is transferred to, i.e., into wait
State waits in default waiting period and continues the connection status for detecting the first interface, performed the step S10 it
Return to step S1 afterwards, the default stand-by period can be by artificially setting;If the first interface and second interface are in same
The network segment then performs step S8.Referring to Fig. 2, being shown as the idiographic flow schematic diagram of step S7, step S7 comprises the following steps:
S71 obtains the IP address value of the first interface and the gateway address value of the first interface and described second connects
The IP address value of mouth and the gateway address value of second interface.
S72 carries out logical AND to the IP address value of the first interface and the gateway address value of the first interface respectively
Operation, the IP address value of the second interface and the gateway address value of second interface carry out logical AND operation to obtain first interface
The network segment and second interface the network segment.
S73 detects the first interface and described according to the network segment of the first interface got and the network segment of second interface
Whether second interface is in the same network segment, if so, step S8 is performed, if it is not, being then transferred to step S10.
S8 is calling the signal process function to reconfigure the network parameter of the routing device so that described the
One interface and second interface are not at the same network segment.
S9 after the network parameter for reconfiguring the routing device, preserves the network parameter reconfigured, sends and restart
The enabled instruction of the routing device, return to step S1, Xun Huan perform the detection Interface status and are handled according to Interface status and connect
The method of mouth failure, until closing the routing device.
In the present embodiment, it is otherwise described to detect Interface status and connect according to Interface status processing unless closing routing device
The method of mouthful failure processing detection first interface connection status always.
Detection Interface status described in the present embodiment simultaneously solves routing and sets according to the method for Interface status Processing Interface failure
Standby side WAN mouthful and LAN mouthfuls in the case that in the same network segment, client can not connect online the problem of, and can be in WAN mouthfuls of companies
When connecing disconnection, user is reminded to plug cable, prevents user from can not connect internet, preferably handles network failure, improved
Resource utilization ratio.
Embodiment two
The present embodiment provides a kind of detection Interface status and according to the system 10 of Interface status Processing Interface failure, applied to tool
There are first interface, second interface, the communication terminal device of multiple network interface cards, network parameter is configured on the communication terminal device.
In the present embodiment, the communication terminal device is router 2, and the first interface 21 is WAN (LAN) interface, and second connects
Mouth 22 is LAN (wide area network) interface.Referring to Fig. 3, being shown as detection Interface status and according to Interface status Processing Interface failure
The theory structure schematic diagram of system.As shown in Fig. 2, described detect Interface status and according to the system of Interface status Processing Interface failure
10 include:Initialization module 101, predefined module 102, acquisition module 103, the first judgment module 104, the second judgment module
105th, alarm module 106, detection module 107, timing module 108, memory module 109, starting module 100.Wherein, the detection
Module 107 includes acquiring unit 1071, logical operations unit 1072 and detection unit 1073.
The initialization module 101 is used to create a Virtual File System when starting the routing device 2.The void
It is the PROC file system that will be created in embedded Linux system start-up course to intend file system.
The predefined module 102 being connected with the initialization module 101 is for pre-defining one to described the
One interface 21 and second interface 22 reconfigure the signal process function of network parameter and to create net when being in the same network segment
The socket function of network socket.Wherein, the signal process function be SIGUSRI signal process functions, the socket letter
It counts as socket functions, i.e. UDP (User Datagram Protocol, User Datagram Protocol) socket.
The acquisition module 103 being connected with the predefined module 102 is used for through the associated input of the web socket
Control data is exported to obtain the title of the network interface card and first interface state return value and be obtained from the PROC file system
Take network interface card information;
First judgment module 104 being connected with the acquisition module 103 be used for according to the network interface card information that acquires and
The title of network interface card judges whether acquired network interface card information matches with the network interface card.That is if the network interface card information with
Network interface card in routing device 2 is corresponding, just illustrates the two matching.
The second judgment module 105 being connected with first judgment module 104 is used to judge in first judgment module
The first interface 21 is judged according to the first interface state return value when acquired network interface card information is matched with the network interface card
Whether in connection status, if the first interface 21 is off, call to send alarm to prompt user institute
It states first interface 21 and the alarm module 106 that interface fault makes user handle the interface fault occurs;If the first interface 21
In connection status, then call to detect the first interface 21 and whether second interface 22 is in the detection mould of the same network segment
Block 107;If the first interface 21 and second interface 22 are in the same network segment, call what the predefined module 102 defined
Signal process function reconfigure the network parameter of the routing device 2 so that the first interface 21 and second interface 22 not
In the same network segment.If first interface 21 and second interface 22 are in the same network segment, then the namely WAN of first interface 21
Mouth can not obtain IP address, then user also just cannot connect to internet, so stilling need call signal processing function again
Configure the network parameter of routing device 2.
106 pieces of the mould of alarm, which performs, sends alarm to prompt interface fault occur for the first interface 21 to make user
A timing module 109 being connected with the alarm module 106, the timing module 109 can be called after handling the interface fault
For setting a default waiting period, the routing device 2 is made to be waited for, waited in default waiting period after
The connection status of the continuous detection first interface 21.
Referring to Fig. 4, being shown as the theory structure schematic diagram of detection module, the detection module 107 includes:
For obtaining the IP of the gateway address value of the IP address value of first interface 21 and first interface 21 and second interface 22
The acquiring unit 1071 of the gateway address value of address value and second interface.
For carrying out logical operation to the IP address value and 21 gateway address value of first interface of the first interface 21 respectively,
The IP address value of the second interface 22 and the gateway address value of second interface 22 carry out logical AND operation to obtain first interface
The logical operations unit 1072 of 21 network segment and the network segment of second interface 22.And
For the network segment of first interface 21 and second interface 22 arrived according to 1072 logical operation of logical operations unit
The network segment detect the detection unit 1073 whether first interface 21 and second interface 22 are in the same network segment.
It is also adjusted after the detection module 107 detects the first interface 21 and second interface 22 is not at the same network segment
With the timing module 109, the routing device is made to be waited for, waited in default waiting period and continue to detect institute
State the connection status of first interface 21.Detect that the first interface 21 and second interface 22 are in the detection module 107
The signal process function for agreeing to after the network segment the predefined module 102 be called to define reconfigures the network of the routing device 2
Parameter makes the memory module 109 preserve again so that the first interface 21 and second interface 22 are not at the same network segment
The network parameter of configuration sends and restarts enabled instruction to the starting module 100 of the routing device 2 its is made to restart the road
By equipment 2.In the present embodiment, it is described to detect Interface status and be constantly according to the system 10 of Interface status Processing Interface failure
The state of the connection status of WAN mouthfuls of detection is until close routing device 2.
Detection Interface status described in the present embodiment is simultaneously solved according to the method and system of Interface status Processing Interface failure
WAN mouthfuls of routing device side and LAN mouthfuls, and can be in the case that in the same network segment, client can not connect online the problem of
When WAN mouthfuls of connections disconnect, user is reminded to plug cable, prevents user from can not connect internet, preferably handle network event
Barrier, improves resource utilization ratio.
So the present invention effectively overcomes various shortcoming of the prior art and has high industrial utilization.
The above-described embodiments merely illustrate the principles and effects of the present invention, and is not intended to limit the present invention.It is any ripe
Know the personage of this technology all can carry out modifications and changes under the spirit and scope without prejudice to the present invention to above-described embodiment.Cause
This, those of ordinary skill in the art is complete without departing from disclosed spirit and institute under technological thought such as
Into all equivalent modifications or change, should by the present invention claim be covered.