可以使用 PHP 连接到远程桌面吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8485029/
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
Possible to connect to Remote Desktop with PHP?
提问by Rob
I've got a few servers that I'd like to connect to every so often to run a program. However, to make it easier, I'd like to make a PHP script connect to each of them via remote desktop and run each of them. Is this possible? If so, where should I start? An example would be lovely.
我有几台服务器,我想经常连接到它们来运行程序。但是,为了方便起见,我想让一个 PHP 脚本通过远程桌面连接到它们中的每一个并运行它们中的每一个。这可能吗?如果是这样,我应该从哪里开始?一个例子会很可爱。
回答by GordonM
In theory you could implement a PHP script that could communicate with a server in the RDP protocol, but I certainly wouldn't want to try to build a script that can do anything meaningful, as RDP is built to expose a remote machine's user interface to the connected client and PHP is built first and foremost to manipulate text.
从理论上讲,您可以实现一个可以与 RDP 协议中的服务器通信的 PHP 脚本,但我当然不想尝试构建一个可以做任何有意义的事情的脚本,因为 RDP 的构建是为了将远程机器的用户界面暴露给连接的客户端和 PHP 首先构建用于操作文本。
If you want a PHP script to remotely control another computer, then SSH is a far more sensible option, as PHP could easily connect to the remote cmputer's CLI and issue commands to the server via shell commands, which are textual and therefore easily generated with PHP.
如果你想要一个 PHP 脚本来远程控制另一台计算机,那么 SSH 是一个更明智的选择,因为 PHP 可以轻松地连接到远程计算机的 CLI 并通过 shell 命令向服务器发出命令,这些命令是文本的,因此很容易用 PHP 生成.
On the other hand, interfacing with the remote computer with RDP would be extremely difficult. Just think about clicking on an icon to get a directory listing for a start. You'd first have to determine where the mouse pointer is, whether the icon you want to click is visible and if so where its bounding box is relative to the mouse pointer. You'd then have to issue commands to move the mouse pointer to within the bounding box, then check that the mouse pointer is in the right place (a local or other remote user might be moving the mouse around) and then issue a pair of clicks with a short delay between them.
另一方面,使用 RDP 与远程计算机连接将非常困难。只需考虑单击一个图标即可开始获得目录列表。您首先必须确定鼠标指针的位置,您要单击的图标是否可见,如果是,则其边界框相对于鼠标指针的位置。然后,您必须发出命令将鼠标指针移动到边界框内,然后检查鼠标指针是否在正确的位置(本地或其他远程用户可能正在四处移动鼠标),然后发出一对之间有短暂延迟的点击。
That's going to be a lot harder than issuing "cd C:\Program Files\" followed by "dir", for example.
例如,这比发出“cd C:\Program Files\”后跟“dir”要困难得多。
回答by Tim Martens
No PHP cannot use RDP to connect to the server. They can use SSH or FTP or a socket to a listening port.
没有 PHP 不能使用 RDP 连接到服务器。他们可以使用 SSH 或 FTP 或套接字到侦听端口。
What you are asking is kinda crazy!!! =)
你问的有点疯狂!!!=)
Edit:
编辑:
Since you insist on doing it here is what you need:
既然你坚持在这里做这就是你所需要的:
[MS-RDPBCGR]: Remote Desktop Protocol: Basic Connectivity and Graphics Remoting Specification
[MS-RDPCR2]: Remote Desktop Protocol: Composited Remoting V2 Specification
[MS-RDPEA]: Remote Desktop Protocol: Audio Output Virtual Channel Extension
[MS-RDPEAI]: Remote Desktop Protocol: Audio Input Redirection Virtual Channel Extension
[MS-RDPECLIP]: Remote Desktop Protocol: Clipboard Virtual Channel Extension
[MS-RDPEDC]: Remote Desktop Protocol: Desktop Composition Virtual Channel Extension
[MS-RDPEDYC]: Remote Desktop Protocol: Dynamic Channel Virtual Channel Extension
[MS-RDPEFS]: Remote Desktop Protocol: File System Virtual Channel Extension
[MS-RDPEGDI]: Remote Desktop Protocol: Graphics Device Interface (GDI) Acceleration Extensions
[MS-RDPELE]: Remote Desktop Protocol: Licensing Extension
[MS-RDPEMC]: Remote Desktop Protocol: Multiparty Virtual Channel Extension
[MS-RDPEPC]: Remote Desktop Protocol: Print Virtual Channel Extension
[MS-RDPEPNP]: Remote Desktop Protocol: Plug and Play Devices Virtual Channel Extension
[MS-RDPEPS]: Remote Desktop Protocol: Session Selection Extension
[MS-RDPERP]: Remote Desktop Protocol: Remote Programs Virtual Channel Extension
[MS-RDPESC]: Remote Desktop Protocol: Smart Card Virtual Channel Extension
[MS-RDPESP]: Remote Desktop Protocol: Serial and Parallel Port Virtual Channel Extension
[MS-RDPEUSB]: Remote Desktop Protocol: USB Devices Virtual Channel Extension
[MS-RDPEV]: Remote Desktop Protocol: Video Redirection Virtual Channel Extension
[MS-RDPEXPS]: Remote Desktop Protocol: XML Paper Specification (XPS) Print Virtual Channel Extension
[MS-RDPNSC]: Remote Desktop Protocol: NSCodec Extension
[MS-RDPRFX]: Remote Desktop Protocol: RemoteFX Codec Extension
You can find all those here: http://msdn.microsoft.com/en-us/library/cc216513(v=PROT.10).aspx
你可以在这里找到所有这些:http: //msdn.microsoft.com/en-us/library/cc216513(v=PROT.10).aspx
With this documentation you can determine the feasibilty of your project.
使用此文档,您可以确定项目的可行性。
回答by sujithayur
I am using
我在用
rdesktop -u username -p password 192.168.1.131 -g 1024x640
in linux, where 192.168.1.131 is the destination ip and 1024x640 is the window size.
在 linux 中,192.168.1.131 是目标 ip,1024x640 是窗口大小。
Also you can use
你也可以使用
rdesktop -u username -p password 192.168.1.131 -f
for full screen.
为全屏。
Don't forget to replace the username and password with your details.
不要忘记用您的详细信息替换用户名和密码。
回答by Cosmo Arun
vmware Esxi uses such a ui page but not with PERL application, After reading the answers it seems a real challenge. I'm working on such a thing for my web based hosts access. If I get something done, I'll be happy to share with you.
vmware Esxi 使用这样的 ui 页面,但不使用 PERL 应用程序,阅读答案后,这似乎是一个真正的挑战。我正在为我的基于网络的主机访问做这样的事情。如果我完成了某件事,我很乐意与您分享。
回答by paulslater19
I think it be best if the servers were running a service that you could connect to. For example they could be running a web service (e.g. php if that's your desired language). You could then connect to that web address through port 80 which could run the applications. Of course you have security concerns, but you should be able to configure them so that they only accept requests from certain IPs. Alternatively you could make the script password-protected
我认为最好是服务器正在运行您可以连接的服务。例如,他们可能正在运行网络服务(例如 php,如果这是您想要的语言)。然后,您可以通过可以运行应用程序的端口 80 连接到该网址。当然,您有安全问题,但您应该能够配置它们,以便它们只接受来自某些 IP 的请求。或者,您可以使脚本受密码保护
回答by haknick
The reason ppl are not recommending RDP to do this is because RDP has no API to do even remotely what you actually want. The easiest way to do this while somehow staying within your requirements, is to install one of the software linked below on the host machines. Then you would need an API to connect:
ppl 不推荐 RDP 这样做的原因是因为 RDP 没有 API 可以远程执行您真正想要的操作。以某种方式满足您的要求的最简单方法是在主机上安装下面链接的软件之一。然后你需要一个 API 来连接:
This: http://www.codeproject.com/KB/system/remoteexec.aspx. In PHP all you would need is something as simple as exec("rexec 123.21.61.12 notepad.exe "\fileserver1\test file.txt") (you can modify it to accept a key for a bit of security)
TeamViewer (free): http://www.teamviewer.com/en/products/remotecontrol.aspxThen you would use TeamViewer WebConnect to connect to via PHP
OpenVPN (open source) Not sure if there is an API that comes with it but I wouldn't be surprised
Log me in (same as above)
Install WAMP on the hosts and then have php run the commands on them. So it would be something like php to php where ur client would call something like curl(127.0.0.1/?key=loooong&command=blah) and the server would run exec("passed command")
这个:http: //www.codeproject.com/KB/system/remoteexec.aspx。在 PHP 中,您只需要 exec("rexec 123.21.61.12 notepad.exe "\fileserver1\test file.txt") (您可以修改它以接受密钥以确保安全)
TeamViewer(免费):http: //www.teamviewer.com/en/products/remotecontrol.aspx然后您将使用 TeamViewer WebConnect 通过 PHP 连接
OpenVPN (开源) 不确定它是否有一个 API,但我不会感到惊讶
登录(同上)
在主机上安装 WAMP,然后让 php 在它们上运行命令。所以它会像 php 到 php 一样,你的客户端会调用 curl(127.0.0.1/?key=loooong&command=blah) 之类的东西,服务器会运行 exec("passed command")
回答by Olaf
Why not use FTP for what you need? then generate and execute files with simple commands microsoft.
为什么不使用 FTP 来满足您的需求?然后使用简单的命令microsoft生成并执行文件。
回答by Timur
I think it would be better to set up daemon/service on server to which you want connect and communicate with it via TCP. In this case, you are free to implement any protocol you want.
我认为最好在要连接的服务器上设置守护程序/服务并通过 TCP 与之通信。在这种情况下,您可以自由地实现您想要的任何协议。
回答by AlfredoVR
Why not running a perl script from a cronjob or execute the programs with the backquotes?
为什么不从 cronjob 运行 perl 脚本或使用反引号执行程序?
回答by wyqydsyq
If all you want to do is to connect to your many servers and run the same program, you could do a one-time upload of a php execute script to all your servers that should exec()
a command from input data (most likely from $_POST
or $_GET
). You then write a local script, which will send the command string to run your program to all the exec scripts on all your servers, so essentially typing the command to run whatever program you need will execute the command on every server.
如果您只想连接到多个服务器并运行相同的程序,您可以一次性将 php 执行脚本上传到所有服务器,该脚本应该exec()
来自输入数据(最有可能来自$_POST
或$_GET
)的命令。然后您编写一个本地脚本,该脚本会将运行您的程序的命令字符串发送到您所有服务器上的所有 exec 脚本,因此基本上键入命令以运行您需要的任何程序将在每台服务器上执行该命令。
Obviously you'll need to require authentication for your exec script so nobody can abuse your servers. Of cause, this whole thing wouldn't be suitable if the program you're running requires much interaction (you did say you wanted to runa program, which implies you want to execute it and leave it to do it's own thing)
显然,您需要对 exec 脚本进行身份验证,以便没有人可以滥用您的服务器。当然,如果您正在运行的程序需要很多交互,那么整个事情就不合适了(您确实说过要运行一个程序,这意味着您要执行它并让它自己做事)