从浏览器打开 PuTTY 客户端的 HTML 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17670067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML code to open PuTTY client from browser
提问by Amistad
I am trying to make a webpage which will have the entire inventory of servers that our team manages in the form of a table. I am using a simple LAMP stack and the inventory input as a CSV file.
我正在尝试制作一个网页,其中包含我们团队以表格形式管理的整个服务器清单。我使用一个简单的 LAMP 堆栈和库存输入作为 CSV 文件。
The table has three columns: Hostname, IP address and device serial number.
该表包含三列:主机名、IP 地址和设备序列号。
While this works perfectly fine, I want to take this a step further and make every IP address in the table a hyperlink, clicking which will open an SSH client, which will connect to that IP address. Any cues to how this can be done? I was hoping there would be something like the the mailto:
tag which opens an email client (Outlook window).
虽然这工作得很好,但我想更进一步,使表中的每个 IP 地址成为一个超链接,单击它会打开一个 SSH 客户端,该客户端将连接到该 IP 地址。关于如何做到这一点的任何提示?我希望会有类似mailto:
打开电子邮件客户端(Outlook 窗口)的标签的东西。
回答by cdelacroix
I've done it following the info of this blog post.
For future reference in case the original page becomes missing, here is the process:
为了将来在原始页面丢失的情况下参考,这里是过程:
you cannot directly map the ssh:// scheme to PuTTY, but you can map it to an intermediary script which will in turn lanch PuTTY with the right arguments. Mine is called putty_ssh.bat and has the following content:
@echo off set var=%1 set extract=%var:~6,-1% "C:\Program Files (x86)\PuTTY\putty.exe" %extract%
the script has to be registered in the registry. You can just create a ssh.reg file with the following content and open it (customizing last line as needed):
REGEDIT4 [HKEY_CLASSES_ROOT\ssh] @="URL:ssh Protocol" "URL Protocol"="" [HKEY_CLASSES_ROOT\ssh\shell] [HKEY_CLASSES_ROOT\ssh\shell\open] [HKEY_CLASSES_ROOT\ssh\shell\open\command] @="\"C:\path\to\putty_ssh.bat\" %1"
您不能直接将 ssh:// 方案映射到 PuTTY,但您可以将其映射到一个中间脚本,该脚本反过来会使用正确的参数启动 PuTTY。我的名为 putty_ssh.bat 并具有以下内容:
@echo off set var=%1 set extract=%var:~6,-1% "C:\Program Files (x86)\PuTTY\putty.exe" %extract%
该脚本必须在注册表中注册。您可以创建一个包含以下内容的 ssh.reg 文件并打开它(根据需要自定义最后一行):
REGEDIT4 [HKEY_CLASSES_ROOT\ssh] @="URL:ssh Protocol" "URL Protocol"="" [HKEY_CLASSES_ROOT\ssh\shell] [HKEY_CLASSES_ROOT\ssh\shell\open] [HKEY_CLASSES_ROOT\ssh\shell\open\command] @="\"C:\path\to\putty_ssh.bat\" %1"
When I click on ssh:// links in web pages, it now opens PuTTY.
当我单击网页中的 ssh:// 链接时,它现在会打开 PuTTY。
回答by Martin Prikryl
PuTTY unfortunately does not associate itselfwith the ssh://
or any other URLs.
不幸的是,PuTTY不会将自己与ssh://
或任何其他 URL相关联。
You can associate an application with a protocol manually. But it's not trivial. For instructions, see below.
您可以手动将应用程序与协议相关联。但这并非微不足道。有关说明,请参见下文。
Easier way is to install WinSCP SFTP client. WinSCP 5.9 and newer registers itself to handle the ssh://
URLand opens the session specified by the URL in PuTTY.
更简单的方法是安装WinSCP SFTP 客户端。WinSCP 5.9 及更新版本自行注册以处理ssh://
URL并在 PuTTY 中打开由 URL 指定的会话。
So basically, if you just install WinSCP, it will make PuTTY handle the ssh://
URLs, without the below manual tweaks.
所以基本上,如果你只安装 WinSCP,它会让 PuTTY 处理ssh://
URL,而不需要下面的手动调整。
(I'm the author of WinSCP)
(我是 WinSCP 的作者)
To register an application manually, see the MSDN article Registering an Application to a URI Scheme.
要手动注册应用程序,请参阅 MSDN 文章将应用程序注册到 URI 方案。
Basically you add a registry key like:
基本上你添加一个注册表项,如:
[HKEY_CLASSES_ROOT\ssh]
@="URL: SSH Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\ssh\DefaultIcon]
@="\"C:\Program Files (x86)\PuTTY\PuTTY.exe\",0"
[HKEY_CLASSES_ROOT\ssh\shell]
[HKEY_CLASSES_ROOT\ssh\shell\open]
[HKEY_CLASSES_ROOT\ssh\shell\open\command]
@="\"C:\Program Files (x86)\PuTTY\PuTTY.exe\""
Though the above passes a whole URL to the PuTTY command-line. And PuTTY does not understand the ssh://
prefix. So you would have to add a wrapper script that strips the ssh://
and passes only a user and a host to PuTTY.
尽管上面将整个 URL 传递给 PuTTY 命令行。而且 PuTTY 不理解ssh://
前缀。因此,您必须添加一个包装脚本,该脚本ssh://
将用户和主机剥离并仅传递给 PuTTY。
For that see:
https://johnsofteng.wordpress.com/2009/05/12/launch-putty-from-browser/
参见:https:
//johnsofteng.wordpress.com/2009/05/12/launch-putty-from-browser/