Method and device for establishing SSH connection
A method of establishing a method and a technology of connecting a port, which is applied in the field of communication and can solve problems such as failure to successfully establish an SSH connection
Active Publication Date: 2017-03-22
HISENSE VISUAL TECH CO LTD
6 Cites 2 Cited by
AI-Extracted Technical Summary
Problems solved by technology
[0004] In view of this, the present invention provides a method and device for establishing an SSH connection to solve the problem in the related art that t...
Abstract
The invention provides a method and a device for establishing a secure shell (SSH) connection. The method comprises the following steps of selecting a plurality of to-be-converted bits from an own MAC address based on a preset selection strategy; converting the to-be-converted bits to a decimal system and obtaining a value corresponding to the converted decimal system; determining a to-be-connected port on a public network server based on the value corresponding to the converted decimal system; and establishing the SSH connection with the public network server based on the to-be-connected port. The to-be-connected port on the public network server is determined based on the unique MAC address, so that the possibility that an SSH server device selects the occupied port as a connection port is smaller in a process of establishing the SSH connection with the public network server, and thus a problem that the SSH server device selects the occupied port to carry out the SSH connection with the public network server to cause a failure to establish the SSH connection successfully in the correlation technique can be effectively solved.
Application Domain
Transmission
Technology Topic
Secure ShellMAC address +3
Image
Examples
- Experimental program(1)
Example Embodiment
[0022] Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the present invention. Rather, they are merely examples of apparatuses and methods consistent with aspects of the invention as recited in the appended claims.
[0023] The terminology used in the present invention is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used herein and in the appended claims, the singular forms "a", "the", and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It should also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0024] It should be understood that although the terms first, second, third, etc. may be used in the present invention to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of the present invention, first information may also be called second information, and similarly, second information may also be called first information. Depending on the context, the word "if" as used herein may be interpreted as "at" or "when" or "in response to a determination."
[0025] See figure 1 , is a networking diagram of an SSH debugging system shown. figure 1 In , the SSH server device can randomly select the port on the public network server as the port to be connected, such as figure 1 port 1, and then the SSH server device can establish an SSH connection with the public network server based on the port to be connected. After the public network server successfully establishes an SSH connection with the SSH server device based on the port to be connected, it can select another port from its own ports as the mapped port of the port to be connected, such as figure 1 Port 2 in . After determining the corresponding mapped port, the public network server can return the mapping relationship between the port to be connected and the mapped port to the corresponding configuration client, and the configuration client can save and display the mapping relationship after receiving the mapping relationship , so that relevant staff can view the mapping relationship and manually establish an SSH connection between the SSH client device and the public network server based on the mapping relationship.
[0026] In related technologies, the public network server can respectively establish SSH connections with multiple SSH server devices. During the process of establishing the SSH connection, the multiple SSH server devices randomly select the port of the public network server for connection. Therefore, when When there are a large number of SSH server devices that need to establish SSH connections with the public network server, it is very likely that the SSH server device selects an occupied port for SSH connection with the public network server. In this case, the SSH server device Failed to successfully establish an SSH connection with the public network server.
[0027] In view of this, the present invention provides a method and device for establishing an SSH connection to solve the problem in the related art that the SSH connection cannot be successfully established because the SSH server device selects an occupied port for SSH connection with the public network server . In the present invention, the SSH server device can first select a plurality of bits to be converted from its own MAC address based on a preset selection strategy, and then convert the plurality of bits to be converted into decimal, and obtain the converted decimal For the corresponding value, the SSH server device can determine the port to be connected on the public network server based on the converted decimal value, and establish an SSH connection with the public network server based on the port to be connected.
[0028] In the present invention, since the port to be connected on the public network server is determined based on the unique MAC address, therefore, the SSH server device selects the possibility of taking up the port as the connection port in the process of establishing an SSH connection with the public network server Smaller, so that it can effectively solve the problem in the related art that the SSH connection cannot be successfully established because the SSH server device selects an occupied port to perform the SSH connection with the public network server.
[0029] see figure 2 , is a flow chart of a method for establishing an SSH connection shown in an embodiment of the present invention. This embodiment is applied to an SSH server device and includes the following steps:
[0030] Step 201: Select a plurality of bits to be converted from its own MAC address based on a preset selection strategy.
[0031] In the present invention, the SSH server device can select a plurality of digits to be converted from its own MAC address based on a preset selection strategy. Wherein, the selection strategy preset by the SSH server device may be a selection strategy customized by relevant personnel, or may be a default selection strategy of the device, which is not limited in the present invention.
[0032] In one embodiment shown, the MAC address of the SSH server device can be 8C-7B-9D-43-50-89, and the SSH server device can select from the MAC address after obtaining its own MAC address. Multiple, for example, 3 bits to be converted, it can be assumed that the default selection strategy of the SSH server device is to select the 1st, 4th and 8th bits from the MAC address as the 3 bits to be converted, then the SSH service The three bits to be converted selected by the terminal device based on the preset selection strategy may be 8, B, and 3.
[0033] It should be noted that in the present invention, the multiple bits to be converted selected by the SSH server device based on a preset selection strategy may or may not be adjacent to each other, which is not limited in the present invention.
[0034] In one embodiment, the SSH server device can obtain the number of connection ports provided by the public network server, and then select a corresponding number of bits to be converted from its own MAC address according to the numerical range to which the number of connection ports belongs.
[0035] The corresponding relationship between the numerical range of the connection port provided by the public network server and the number of bits to be converted selected by the SSH server device from its own MAC address can be preset. For example, it can be assumed that the numerical range of the connection port provided by the public network server is When the value ranges from 0 to 255, the SSH server device should select 2 digits to be converted; when the value range of the connection port provided by the public network server is 256 to 4095, the SSH server device should select 3 digits to be converted; and when the public network When the value range of the connection port provided by the server is 4096 to 65536, the SSH server device selects 4 corresponding bits to be converted.
[0036]Also taking the MAC address of the SSH server device as 8C-7B-9D-43-50-89 as an example, it can be assumed that the number of connection ports provided by the public network server obtained by the SSH server device is 60,000, and the SSH server device can be accessed from Select 4 bits to be converted from its own MAC address.
[0037] In one embodiment, the SSH server device can divide its own MAC address into several segments of address parts in a specified order based on a preset selection strategy, and then select a segment of address parts as the plurality of bits to be converted. Wherein, the designated order may be a front-to-back order, or a back-to-front order, etc., which is not limited in the present invention.
[0038] Taking the SSH server device as an example to select 4 bits from its own MAC address as multiple bits to be converted, the SSH server device can divide its own MAC address into three segments in the order from front to back based on the preset selection strategy. Partial bits, wherein, each part of the address part may include 4 bits, and then the SSH server device may select the last part of the address part from the 3 part addresses of the bits as the 4 bits to be converted.
[0039] It can be assumed that the MAC address of the SSH server device is 8C-7B-9D-43-50-89, then the SSH server device can first divide the MAC address into 3 sections in order from front to back: the first section: 8C- 7B; second paragraph: 9D-43 and third paragraph: 50-89. Then, the SSH server device can select the last segment, that is, the third segment, as the 4 bits to be converted.
[0040] Step 202: Convert the plurality of bits to be converted into decimal, and obtain a value corresponding to the converted decimal.
[0041] In the present invention, after the SSH server device selects a plurality of digits to be converted, it can convert the plurality of converted digits into decimal, and obtain the value corresponding to the converted decimal.
[0042] In one embodiment, it can be assumed that the SSH server device has selected 4 bits to be converted, and the 4 bits to be converted are 50-89, then the SSH server device can convert the 4 converted bits into decimal, and obtain The converted decimal corresponds to the value 20617.
[0043] Step 203: Determine the port to be connected on the public network server based on the converted decimal value.
[0044] In the present invention, after the SSH server device acquires the converted decimal value, it can determine the port to be connected on the public network server based on the corresponding value.
[0045] In one embodiment, it can be assumed that the converted decimal value obtained by the SSH server device is 20617, and it can be determined that the port to be connected on the public network server is port 20617.
[0046] Step 204: Establish an SSH connection with the public network server based on the port to be connected.
[0047] In the present invention, after determining the port to be connected on the public network server, the SSH server device can establish an SSH connection with the public network server based on the port to be connected.
[0048] In one embodiment shown, the port to be connected on the public network server determined by the SSH server device based on its own MAC address may be port 20617, then the SSH server device may be based on the 20617 port on the public network server and the public network The server establishes an SSH connection.
[0049] In one embodiment, when the SSH server device establishes an SSH connection with the public network server on the port to be connected determined based on its own MAC address, the establishment fails. For example, the port to be connected is an occupied port, that is, another SSH server device has successfully established an SSH connection with the public network server based on the port to be connected. At this time, the SSH server device cannot communicate with the public network server based on the port to be connected. The server successfully establishes an SSH connection.
[0050] In the present invention, if the SSH server device does not successfully establish an SSH connection with the public network server based on the port to be connected, the SSH server device can reselect a plurality of bits that are different from the selected plurality of bits to be converted from its own MAC address. or completely different new bits to be converted, and re-determine the port to be connected on the public network server based on the multiple new bits to be converted.
[0051] Wherein, the specific process of the SSH server device re-determining the ports to be connected on the public network server based on the multiple new bits to be converted is the same as the above-mentioned embodiment, and the present invention will not repeat them here.
[0052] In one embodiment, also taking the MAC address of the above-mentioned SSH server device as 8C-7B-9D-43-50-89 as an example, the SSH server device can select 4 bits to be converted from its own MAC address, and The 4 bits to be converted can be the 1st, 3rd, 7th, and 8th bits, then the 4 bits to be converted selected by the SSH server device can be 8, 7, 4, and 3, and the SSH server device The port to be connected on the public network server determined based on the four bits to be converted may be port 34627.
[0053] It can be assumed that port 34627 on the public network server is an occupied port. When the SSH server device establishes an SSH connection with the public network server based on port 34627, it cannot successfully establish an SSH connection with the public network server. At this time, the SSH server device can reselect 4 bits to be converted from its own MAC address that are partially or completely different from the selected 4 bits to be converted. For example, the first four bits 8C- 7B is used as 4 new digits to be converted, and then the SSH server device can convert the 4 new digits to be converted into decimal, and obtain the value 35963 corresponding to the converted decimal, and the SSH server device can base on the converted decimal The corresponding value is 35963 to re-determine the port to be connected on the public network server as port 35963, and establish an SSH connection with the public network server based on port 35963.
[0054] Of course, if the plurality of bits to be converted selected by the SSH server device is a certain segment of the address segment in the multi-segment address segment bits based on its own MAC address, the SSH server device can be based on the above-mentioned address segment determined based on the segment address segment. When the port to be connected has not successfully established an SSH connection with the public network server, reselect a section of address section bits from the above-mentioned multi-section address section bits as a plurality of new bits to be converted, wherein the reselected section address section bits of this section are not The selected address part bits above.
[0055] Also taking the MAC address of the SSH server device as 8C-7B-9D-43-50-89 as an example, the SSH server device can divide the MAC address into 3 segments in order from front to back, and select The last part of the address part is used as a plurality of bits to be converted. It can be assumed that the port to be connected on the public network server determined by the SSH server device based on the last part of the address has not successfully established an SSH connection with the public network server, then the SSH server device can reselect an address from the above three part of the address part Partial bits are used as a plurality of new bits to be converted, wherein, the reselected address partial bits of this segment are not the last segment address partial bits. It can be assumed that the part of the address part reselected by the SSH server device is the second part of the address part 9D-43, then the SSH server device can convert the multiple bits to be converted into decimal, and obtain the value corresponding to the converted decimal 40259, the SSH server device can re-determine the port to be connected on the public network server as port 40259 based on the converted decimal value 40259, and establish an SSH connection with the public network server based on port 40259.
[0056] In the present invention, the SSH server device can first select a plurality of digits to be converted from its own MAC address based on a preset selection strategy, and then convert the plurality of digits to be converted into decimal, and obtain the converted decimal correspondence value, the SSH server device can determine the port to be connected on the public network server based on the converted decimal value, and establish an SSH connection with the public network server based on the port to be connected.
[0057] In the present invention, since the port to be connected on the public network server is determined based on the unique MAC address, therefore, the SSH server device selects the possibility of taking up the port as the connection port in the process of establishing an SSH connection with the public network server Smaller, so that it can effectively solve the problem in the related art that the SSH connection cannot be successfully established because the SSH server device selects an occupied port to perform the SSH connection with the public network server.
[0058] Based on the same inventive concept as the above method, the embodiment of the present invention also provides an embodiment of an apparatus for establishing an SSH connection.
[0059] The apparatus for establishing an SSH connection of the present invention can be applied to devices including SSH server devices. Wherein, the device for establishing the SSH connection may be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation through the processor where it is located. From an application level, such as image 3 Shown is a block diagram of the hardware structure of the device for establishing the SSH connection in the embodiment of the present invention, except image 3 In addition to the shown processor, network interface, memory and non-volatile memory, other hardware may also be included, such as a forwarding chip responsible for processing messages.
[0060] like Figure 4 Shown is a block diagram of an apparatus for establishing an SSH connection according to an exemplary embodiment of the present invention. The device is applied to an SSH server device, and the device includes: a selection module 410 , a conversion module 420 , a determination module 430 and an establishment module 440 .
[0061] Wherein, the selection module 410 is used to select a plurality of bits to be converted from its own MAC address based on a preset selection strategy;
[0062] A conversion module 420, configured to convert the plurality of bits to be converted into decimal, and obtain a value corresponding to the converted decimal;
[0063] A determining module 430, configured to determine the port to be connected on the public network server based on the converted decimal value;
[0064] An establishing module 440, configured to establish an SSH connection with the public network server based on the port to be connected.
[0065] In an optional implementation manner, the selecting module 410 may be specifically used for:
[0066] Obtain the number of connection ports provided by the public network server;
[0067] Select a corresponding number of bits to be converted from its own MAC address according to the numerical range to which the number of connection ports belongs.
[0068] In an optional implementation, the selecting module 410 may be further used to:
[0069] If the SSH connection is unsuccessfully established with the public network server based on the port to be connected, reselect a plurality of partially different or completely different new bits to be converted from the MAC address of the selected plurality of bits to be converted;
[0070] The determination module 430 may be further used for:
[0071] A port to be connected on the public network server is re-determined based on the plurality of new bits to be converted.
[0072] In an optional implementation, the plurality of bits to be converted are 4 bits to be converted, and the selection module 410 can be specifically used for:
[0073]Based on the preset selection strategy, the own MAC address is divided into 3 sections of address parts according to the specified order; wherein, each section of address sections includes 4 bits;
[0074] Select the last part of the address part as the 4 bits to be converted;
[0075] The selection module 410 can be further used for:
[0076] If the SSH connection is unsuccessfully established with the public network server based on the port to be connected, reselect a section of new address part bits as 4 new bits to be converted from the 3 sections of address parts based on the MAC address division of the self; wherein, The segment new address portion bits are not the last segment address portion bits.
[0077] In the present invention, the SSH server device can first select a plurality of bits to be converted from its own MAC address based on a preset selection strategy, and then convert the plurality of bits to be converted into decimal, and obtain the converted decimal For the corresponding value, the SSH server device can determine the port to be connected on the public network server based on the converted decimal value, and establish an SSH connection with the public network server based on the port to be connected.
[0078] In the present invention, since the port to be connected on the public network server is determined based on the unique MAC address, therefore, the SSH server device selects the possibility of taking up the port as the connection port in the process of establishing an SSH connection with the public network server Smaller, so that it can effectively solve the problem in the related art that the SSH connection cannot be successfully established because the SSH server device selects an occupied port to perform the SSH connection with the public network server.
[0079] For the implementation process of the functions and effects of each module in the above-mentioned device, please refer to the implementation process of the corresponding steps in the above-mentioned method for details, and details will not be repeated here.
[0080] As for the device embodiment, since it basically corresponds to the method embodiment, for related parts, please refer to the part description of the method embodiment. The device embodiments described above are only illustrative, and the modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in One place, or it can be distributed to multiple network modules. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution of the present invention. It can be understood and implemented by those skilled in the art without creative effort.
[0081] The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the present invention. within the scope of protection.
PUM


Description & Claims & Application Information
We can also present the details of the Description, Claims and Application information to help users get a comprehensive understanding of the technical details of the patent, such as background art, summary of invention, brief description of drawings, description of embodiments, and other original content. On the other hand, users can also determine the specific scope of protection of the technology through the list of claims; as well as understand the changes in the life cycle of the technology with the presentation of the patent timeline. Login to view more.