使用远程计算机通过jupyterlab打开网站(类似于代理)
我通过ssh
连接到正在运行Jupyterlab
的远程计算机。当我在jupyterlab
中运行以下代码时,我会看到本地计算机的IP地址:
from IPython.display import IFrame
IFrame(src="https://whatismyipaddress.com/", width='100%', height='500px')
有没有一种方法可以使用远程计算机的连接访问网站?理想情况下,该解决方案将使我能够通过iframe
与网站进行交互,并且上面的摘要将显示远程计算机的IP。
I connect via SSH
to a remote machine that is running JupyterLab
. When I run the following code in JupyterLab
I see the IP address of my local machine:
from IPython.display import IFrame
IFrame(src="https://whatismyipaddress.com/", width='100%', height='500px')
Is there a way to access the website using the remote machine's connection? Ideally, the solution will allow me to interact with the website via the IFrame
, and the snippet above would display IP of the remote machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iframe
方法使用< iframe>
生成了HTML小部件,该小部件使用本地浏览器的连接加载网站。如果您使用Python代码,则该连接是由Jupyter内核正在运行的远程计算机进行的。以下代码应显示远程计算机的IP地址:如果您确实需要使用远程计算机的连接访问网站,则可以设置SSH Dynamic Forward(即使用
ssh -d localhost:8080 Remote_machine ),然后指示您的浏览器使用
local-Host
port 8080上的生成的袜子5代理连接到Internet。让您为每个主机定义自定义规则。在线应该有很多教程如何进行设置。如果您与远程计算机有稳定的连接,则通常可以很好地工作并且相当快。The
IFrame
method generates a HTML widget with an<iframe>
, which loads the website using your local browser's connection. If you use python code instead, the connection is made from your remote machine, on which the jupyter kernel is running. The following code should display the IP address of your remote machine:If you really need to access the website using your remote machine's connection, you could set up an SSH dynamic forward (i.e. use
ssh -D localhost:8080 remote_machine
) and then instruct your browser to connect to the internet using the generated SOCKS5 proxy onlocalhost
port 8080. Most browsers support this natively, but there are also handy add-ons such as Proxy SwitchyOmega, which let you define custom rules for each host. There should be plenty of tutorials online how to set this up. If you have a stable connection to your remote machine, this usually works very well and is reasonably fast.