Disclosure of Invention
The invention aims to provide a method and a device for inquiring equipment information, equipment for inquiring the equipment information and a computer readable storage medium, which are used for realizing the purpose of inquiring the equipment information with higher efficiency through lower cost.
In order to achieve the above object, an embodiment of the present invention provides a method for querying device information, including:
creating a preset number of threads in the range of the target network segment;
inquiring a command group corresponding to the type of the equipment to which each equipment in the target network segment belongs, and sending an inquiry command in the command group to each equipment through the thread;
and judging whether return information exists or not, and if so, recording the return information.
After a preset number of threads are created in the range of the target network segment, the method further comprises the following steps:
sending a connection request to each device through the thread according to the IP address and the port number of each device in the target network segment range so that each device can return a request result;
and judging whether connected equipment which is successfully connected exists in the range of the target network segment according to the request result, and inquiring a command group corresponding to the equipment type of the connected equipment if the connected equipment exists in the range of the target network segment.
If the connection of the target device in the target network segment range fails, the method further comprises the following steps:
judging whether the connection times of the target equipment reach preset connection times or not;
and if not, sending the connection request to the target equipment through the thread again.
Before querying the command group corresponding to the device type of each device in the target network segment range, the method further includes:
inquiring a user name password group corresponding to the type of the connected equipment, and logging in the connected equipment by using the user name password in the user name password group through the thread;
and judging whether the connected equipment has logged-in equipment which logs in successfully, if so, inquiring a command group corresponding to the equipment type of the logged-in equipment.
Before querying the username password group corresponding to the device type to which the connected device belongs, the method further includes:
and determining the equipment type of the connected equipment according to the request result.
In order to achieve the above object, an embodiment of the present invention provides an apparatus for querying device information, including:
the creating module is used for creating threads with preset number in the range of the target network segment;
the query module is used for querying a command group corresponding to the type of the equipment to which each equipment in the target network segment belongs and sending query commands in the command group to each equipment through the thread;
and the recording module is used for judging whether return information exists or not, and recording the return information if the return information exists.
Wherein, still include:
the connection module is used for sending a connection request to each device through the thread according to the IP address and the port number of each device in the target network segment range so that each device can return a request result;
and the first judgment module is used for judging whether connected equipment which is successfully connected exists in the target network segment range according to the request result, and if so, the inquiry module is triggered.
Wherein, still include:
the login module is used for inquiring a user name password group corresponding to the type of the connected equipment and logging in the connected equipment by using the user name password in the user name password group through the thread;
and the second judgment module is used for judging whether the connected equipment has logged-in equipment which logs in successfully or not, and if so, triggering the query module.
In order to achieve the above object, an embodiment of the present invention provides an apparatus for querying device information, including:
the memorizer, is used for storing the information inquiry procedure;
and the processor is used for realizing the steps of any one of the equipment information inquiring methods when the information inquiring program is executed.
To achieve the above object, an embodiment of the present invention provides a computer-readable storage medium, on which an information query program is stored, and the information query program, when executed by a processor, implements the method for querying device information as described in any one of the above.
According to the scheme, the method for inquiring the equipment information, provided by the embodiment of the invention, comprises the following steps: creating a preset number of threads in the range of the target network segment; inquiring a command group corresponding to the type of the equipment to which each equipment in the target network segment belongs, and sending an inquiry command in the command group to each equipment through the thread; and judging whether return information exists or not, and if so, recording the return information. Therefore, the method for inquiring the equipment information provided by the embodiment of the invention adopts multithreading to concurrently acquire the equipment information of the target equipment in the target network segment range, and realizes that the equipment information is inquired at higher efficiency through lower cost. The invention also discloses a device for inquiring the equipment information, equipment for inquiring the equipment information and a computer readable storage medium, which can also realize the technical effects.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention discloses a method for inquiring equipment information, which realizes the inquiry of the equipment information with higher efficiency through lower cost.
Referring to fig. 1, a flowchart of a method for querying device information according to an embodiment of the present invention is shown in fig. 1, and includes:
s101: creating a preset number of threads in the range of the target network segment;
in a specific implementation, for a given target network segment range, a preset number of threads are created according to a given number of concurrent connections, for example, 10 concurrent Socket threads may be created within the target network segment range 172.16.1.0 to 172.16.1.255.
Socket, also called Socket, is one of the basic technologies for computer network communication. Most of the network-based software such as browser, instant messenger and even P2P download today are based on Socket. Socket is an intermediate software abstraction layer for the application layer to communicate with the TCP/IP suite of protocols, which is a set of interfaces. In a design mode, Socket is actually a facade mode, a complex TCP/IP protocol family is hidden behind a Socket interface, for a user, a group of simple interfaces are all, and the Socket organizes data to accord with a specified protocol.
S102: inquiring a command group corresponding to the type of the equipment to which each equipment in the target network segment belongs, and sending an inquiry command in the command group to each equipment through the thread;
s103: and judging whether return information exists or not, if so, recording the return information, and if not, ending the process.
In a specific implementation, through the created concurrent Socket thread, a command is sequentially sent to each device from a command group, which may use the query device information, of the device type to which each device in the target network segment belongs until the device information is returned. If some equipment has the return information, the inquiry is successful, the return information corresponding to the equipment is recorded, and the equipment state is set as the inquiry success. If all the commands of a certain device fail to be tried, the state of the device is set as query failure.
In the above example, 10 concurrent Socket threads query the device information of 10 devices at the same time, and when there is a returned result or a device corresponding to a certain thread is determined to be failed in querying, the thread continues to query the device information of the target network segment except the 10 devices until all the devices in the target network segment are queried.
The method for inquiring the equipment information provided by the embodiment of the invention adopts multithreading to concurrently acquire the equipment information of the target equipment in the range of the target network segment, thereby realizing the inquiry of the equipment information with higher efficiency through lower cost.
The embodiment of the invention discloses a method for inquiring equipment information, and compared with the previous embodiment, the embodiment further explains and optimizes the technical scheme. Specifically, the method comprises the following steps:
referring to fig. 2, a flowchart of another method for querying device information according to an embodiment of the present invention is shown in fig. 2, and includes:
s201: creating a preset number of threads in the range of the target network segment;
s221: sending a connection request to the target equipment through the thread according to the IP address and the port number of the target equipment within the range of the target network segment so that the target equipment can return a request result;
s222: judging whether connected equipment which is successfully connected exists in the target network segment range according to the request result, if so, entering S231, and if not, setting the state of the equipment in the target network segment range as connection failure;
in a specific implementation, before sending a command in a command group to each device in a target network segment, the devices need to be connected through Socket threads. Connecting a plurality of devices through multithread Socket in an asynchronous communication mode according to the IP address and the port number of the target device, processing according to a request result returned by the target device in a thread, if the connection is successful, the target device is a connected device, and S231 is entered, and if the connection is failed, the state of the target device is set as connection failure.
S231: determining the equipment type of the connected equipment according to the request result;
in a specific implementation, the device may directly notify the processor of the type of the device through the request result, so that the processor determines the device type of the connected device through the request result, and of course, the processor may also determine the device type of the connected device through other manners, which is not limited herein.
S232: inquiring a user name password group corresponding to the type of the connected equipment, and logging in the connected equipment by using the user name password in the user name password group through the thread;
s233: judging whether the connected equipment has logged-in equipment which logs in successfully or not, if so, entering S204, and if not, setting the state of the connected equipment as login failure;
after the connected equipment is successfully connected, sequentially trying each group of user name and password from the user name and password group possibly used by the equipment type to which each connected equipment belongs until login is successful, and if all the user name and password groups are failed to login, setting the state of the connected equipment as login failure.
It is to be understood that the thread used for logging in the connected device may be a thread connected to the device, or another thread may be reassigned to the device for logging in, and is not limited in particular herein.
S204: inquiring a command group corresponding to the type of the equipment to which the logged equipment belongs, and sending an inquiry command in the command group to the logged equipment through the thread;
s205: and judging whether the logged-in equipment has equipment with return information or not, if so, recording the return information corresponding to the equipment with the return information, and if not, setting the state of the logged-in equipment as query failure.
On the basis of the foregoing embodiment, as a preferred implementation, if the target device within the target network segment fails to connect, the method further includes:
judging whether the connection times of the target equipment reach preset connection times or not;
and if not, sending the connection request to the target equipment through the thread again.
If the target device in the target network segment fails to be connected, the previous thread is continuously used for connecting the target device until the preset connection times are reached, and if the target device still fails to be connected, the state of the target device is set as the connection failure.
The apparatus for querying device information according to the embodiments of the present invention is introduced below, and the apparatus for querying device information described below and the method for querying device information described above may refer to each other.
Referring to fig. 3, a structure diagram of an apparatus for querying device information according to an embodiment of the present invention is shown in fig. 3, and includes:
a creating module 301, configured to create a preset number of threads in a target network segment range;
a query module 302, configured to query a command group corresponding to a device type to which each device in the target network segment belongs, and send a query command in the command group to each device through the thread;
the recording module 303 is configured to determine whether there is return information, and record the return information if there is the return information.
The device for inquiring the equipment information provided by the embodiment of the invention adopts multithreading to concurrently acquire the equipment information of the target equipment in the target network segment range, thereby realizing the inquiry of the equipment information with higher efficiency through lower cost.
In addition to the above embodiments, as a preferred embodiment, the method further includes:
the connection module is used for sending a connection request to each device through the thread according to the IP address and the port number of each device in the target network segment range so that each device can return a request result;
and the first judgment module is used for judging whether connected equipment which is successfully connected exists in the target network segment range according to the request result, and if so, the inquiry module is triggered.
In addition to the above embodiments, as a preferred embodiment, the method further includes:
the login module is used for inquiring a user name password group corresponding to the type of the connected equipment and logging in the connected equipment by using the user name password in the user name password group through the thread;
and the second judgment module is used for judging whether the connected equipment has logged-in equipment which logs in successfully or not, and if so, triggering the query module.
The present application further provides a device for querying device information, referring to fig. 4, a structure diagram of a device for querying device information provided in an embodiment of the present invention is shown in fig. 4, and includes:
a memory 401 for storing an information inquiry program;
the processor 402, when executing the information query program, may implement the steps provided in the above embodiments. Of course, the server may also include various network interfaces, power supplies, and the like.
The device for inquiring the device information provided by the embodiment of the invention adopts multithreading to concurrently acquire the device information of the target device in the range of the target network segment, thereby realizing the purpose of inquiring the device information with higher efficiency through lower cost.
The present application further provides a computer-readable storage medium, on which an information query program is stored, and when the information query program is executed by a processor, the steps provided by the above embodiments can be implemented. The storage medium may include: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
It is further noted that, in the present specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.