使用外部 URL 时访问内部 URL

发布于 2024-10-31 06:18:50 字数 765 浏览 2 评论 0原文

我正在开发一个界面来显示哪些 VNC 网络站处于活动状态,并提供该网络界面的链接。

示例:站 1 是:端口 5800 上的 http://192.168.1.1

如果我在本地网络上运行它,它工作正常,由于所有计算机都在该本地网络上,因此我需要一种从外部 IP 进行这项工作的方法。

无论如何,是否可以将会话重定向到框架或将其保留在本地的东西?

这是我所做的一个测试,在本地网络上工作正常,在远程它只能工作一半:

$station1 = @fsockopen("192.168.1.1", 5800);

if ($station1) {
    echo "<a href='http://192.168.1.1:5800'>Station 1 active.</a>";
    echo "<br />";
        fclose($station1);
    } else {
        echo "Station 1 is inactive.";
    echo "<br />";
    }

'fsockopen' 返回 TRUE,因为它是在“服务器端”执行的,但单击生成的链接会失败,因为它是执行的在“客户端”,例如浏览器

有什么方法可以解决这个问题吗?有什么想法吗?

I am developing an interface to show what VNC-web stations are active and providing a link to that web interface.

Example: Station 1 is: http://192.168.1.1 on port 5800

If I run this on my local network it works fine, since all the computers are on that local network, what I need is a way to have this work from an external IP.

Is there anyway to redirect the session to a frame or something that keeps it local?

Here is a test I made that works fine on the local network, remotely it works only half-way:


$station1 = @fsockopen("192.168.1.1", 5800);

if ($station1) {
    echo "<a href='http://192.168.1.1:5800'>Station 1 active.</a>";
    echo "<br />";
        fclose($station1);
    } else {
        echo "Station 1 is inactive.";
    echo "<br />";
    }

'fsockopen' returns TRUE since it is executed 'server side' but clicking on the resulting link fails since it is executed on the 'client side' e.g. browser

Any way to work around this? Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

旧时光的容颜 2024-11-07 06:18:50

您必须在路由器中设置端口转发,并让 VNC 在不同的端口上运行在每台机器上。将端口号映射到内部 IP 可能是最明智的做法,例如:

 Port 5801 -> 192.168.1.1
 Port 5802 -> 192.168.1.2
 Port 5803 -> 192.168.1.3
 etc.

如果您随后从外部调用该页面(例如使用动态 IP),则必须从 PHP 内部找出您的动态 IP(请参阅例如此处了解如何执行此操作),然后链接到每个端口。

<a href="123.123.123.123:5801">Station 1 active.</a>
<a href="123.123.123.123:5802">Station 2 active.</a>
<a href="123.123.123.123:5803">Station 3 active.</a>

如果不将 VNC 映射到不同的端口,就无法做到这一点。对于外部 IP,仅存在一个 IP 地址。 LAN 的内部 IP 毫无意义,外部呼叫者也无法访问。

You will have to set up port forwarding in your router, and have VNC run on a different port on every machine. It might be wisest to map the port number to the internal IP, for example:

 Port 5801 -> 192.168.1.1
 Port 5802 -> 192.168.1.2
 Port 5803 -> 192.168.1.3
 etc.

if you then call the page from the outside (e.g. using a dynamic IP), you'll have to find out your dynamic IP from within PHP (see e.g. here for how to do that), and then link to each port.

<a href="123.123.123.123:5801">Station 1 active.</a>
<a href="123.123.123.123:5802">Station 2 active.</a>
<a href="123.123.123.123:5803">Station 3 active.</a>

there is no way to do this without mapping VNC to different ports. To an outside IP, only one IP address exists. The LAN's internal IPs are meaningless, and unreachable to a caller from the outside.

蓝眼睛不忧郁 2024-11-07 06:18:50

您也许可以对 http://www.whatismyip.com/ 进行网络调用并抓取外部 IP 地址然后使用它......但是,只有当网络服务器是您正在查询的服务器时,这才有效。如果不是,它会变得很棘手......并且根据路由,它可能会变得非常棘手......所以如果每个内部IP都有不同的外部IP那么好吧它可能会工作但如果没有那么你必须控制请求的获取方式路由...

假设您有

192.168.1.1

192.168.1.2

192.168.1.3

并且它们连接到连接到互联网的家庭无线路由器...通过您的电缆调制解调器,那么所有 3 个路由器将具有相同的 IP您网络之外的人,事实上很可能您的路由器不允许人们回拨到您的网络。您必须将路由器配置为将请求转发到各个端口以到达特定的内部 IP 地址。

因此,如果不知道这个路由是如何设置的,回答这个问题是非常困难的

you could perhaps make a web call to http://www.whatismyip.com/ and scrape the external IP address and then use that... however that only works if the webserver is the one you are querying. If not it gets tricky... and depending on the routing it can get really tricky... so if each internal IP has a different external IP then ok it might work but if not then you have to have control over how the requests get routed...

So say you have

192.168.1.1

192.168.1.2

192.168.1.3

and they are connected to your home wireless router which is connected to the internet.... via say your cable modem then all 3 would have the same IP to folks outside your network and in fact most likely your router wouldn't allow folks to call back into your network. You would have to configure your router to forward requests to various ports to go to specific internal IP addresses.

So without knowing how this routing is setup answering this question is very difficult

┾廆蒐ゝ 2024-11-07 06:18:50

尝试使用此代码进行测试(您会收到一条错误消息,告诉您出了什么问题):
使用普通路由器也无法从网络内部访问您的 WAN IP,使用 WAN IP 连接到互联网,您必须确定其是本地网络还是 WAN 网络,然后相应地更改 IP(加上将所有 WAN 流量路由到服务器) 。

    <?php
if(substr($_SERVER['SERVER_ADDR'], -3)=="1.1"){$server=$_SERVER['SERVER_ADDR'];}else{$server='123.123.YOUR.WAN123.123'}
    $fp = fsockopen($server, 5800, $errno, $errstr);
    if (!$fp) {
        echo "ERROR: $errno - $errstr<br />\n";
    } else {
        echo "<a href='http://'.$server.':5800'>Station 1 active.</a>";
        fclose($fp);
    }
    ?> 

try this code to test, (your get an error telling you whats wrong):
also accessing your WAN ip from inside the network using the WAN ip to connect to the internet cant be done with normal routers you would have to determine if its localnetwork or WAN network then change the ip accordingly (plus route all WAN traffic to the server).

    <?php
if(substr($_SERVER['SERVER_ADDR'], -3)=="1.1"){$server=$_SERVER['SERVER_ADDR'];}else{$server='123.123.YOUR.WAN123.123'}
    $fp = fsockopen($server, 5800, $errno, $errstr);
    if (!$fp) {
        echo "ERROR: $errno - $errstr<br />\n";
    } else {
        echo "<a href='http://'.$server.':5800'>Station 1 active.</a>";
        fclose($fp);
    }
    ?> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文