使用远程计算机通过jupyterlab打开网站(类似于代理)

发布于 2025-02-04 17:28:51 字数 390 浏览 3 评论 0原文

我通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2025-02-11 17:28:51

iframe方法使用< iframe>生成了HTML小部件,该小部件使用本地浏览器的连接加载网站。如果您使用Python代码,则该连接是由Jupyter内核正在运行的远程计算机进行的。以下代码应显示远程计算机的IP地址:

import requests
print(requests.get('https://ipinfo.io').json())

如果您确实需要使用远程计算机的连接访问网站,则可以设置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:

import requests
print(requests.get('https://ipinfo.io').json())

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 on localhost 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文