根据 IP 地址唯一识别路由器后面的机器

发布于 2024-08-30 00:44:12 字数 666 浏览 6 评论 0原文

首先介绍一些背景。我在局域网中的每台计算机上都安装了 .net 客户端代理。他们也在同一局域网上与我的中央服务器[网站]进行交互。

对于我的网站来说,弄清楚哪些机器可以相互通信非常重要。例如,一个子网的机器不能在不配置路由器等的情况下直接与另一子网的机器通信。但同一子网中的机器应该能够直接相互通信。

我面临的问题是当局域网设置如图 1 所示时。

图 1

由于 Comp1、Comp2 和 Comp3 位于路由器后面,因此它们的 IP 地址为 192.168.1.2 到 192.168.1.4。这些机器上的客户端代理将相同的 IP 地址报告回服务器。但是,计算机 Comp4、Comp5 也具有相同的 ip 地址。

因此,就我的服务器而言,有 2 台机器具有相同的 ip 地址。不仅如此,因为所有机器的子网掩码都是255.255.255.0,所以我的服务器误认为Comp1可以直接与Comp5通信,这是不可能的。

那么,我该如何解决这个问题呢?我需要在客户端或服务器中更改哪些内容,以便我可以支持这种情况。这两件事是我唯一能控制的。

Some background first. I have a .net client agent installed on each of the machines in the lan. They are interacting with my central server [website] also on the same lan.

It is important for my website to figure out which of the machines can talk to each other. For example, machines of one subnet cannot directly talk to machines of another subnet without configuring the routers and such. But machines in the same subnet should be able to talk to each other directly.

The problem I am facing is when the lan setup is like in Figure 1.

Figure 1

Because Comp1, Comp2 and Comp3 are behind a router, they have got the ipaddress 192.168.1.2 till 192.168.1.4. My client agent on these machines report the same ipaddress back to the server. However, machines Comp4, Comp5 also have the same ipaddresses.

Thus, as far as my server is concerned, there are 2 machines with the same ipaddress. Not just that, because the subnet mask is 255.255.255.0 for all machines, my server is fooled into thinking that Comp1 can directly talk to Comp5, which is not possible.

So, how do I solve this? What do I need to change in my client or in my server, so that I can support this scenario. These two are the only things in my control.

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

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

发布评论

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

评论(3

红颜悴 2024-09-06 00:44:13

编辑:似乎网络图
过于简化,可能有
多个路由器/子网级别。我的
原来的答案不会处理这个
设想。另外,随着限制
仅修改客户端应用程序或服务器
应用程序并且不篡改
路由器和防火墙使
更难了。

EDIT2:使用“arp -a”您可以提取
路由器的 MAC 地址。如果
客户端应用程序可以设法做到这一点
谜题解决了

客户端应用程序知道本地计算机地址并将其传递给服务器应用程序。

当连接进入时,服务器应用程序知道远程地址。这可以是机器地址或路由器地址。

根据这两个值,您可以计算出您所要求的内容。

例如:

Server app receives connection from 10.10.10.2 with client supplying 192.168.1.2

Server app receives connection from 10.10.10.3 with client supplying 192.168.1.3

“远程地址”区分子网。

因此,您需要弄清楚如何提取客户端连接的远程地址。如果您在服务器应用程序中使用任何流行的 Web 技术,那么这非常简单。

EDIT: Seems that the network diagram
is over simplified and there could be
multiple router/subnet levels. My
original answer will not handle this
scenario. Also, with the restriction
of modifying only the client app or server
app and not tampering with the
routers and firewalls makes
it more difficult.

EDIT2: Using 'arp -a' you can extract
the MAC address of the router. If the
client apps can manage to do this then
the puzzle is solved!

The client app knows the local machine address and passes it to the server app.

The server app knows the remote address when a connection comes in. This would be machine address or a router address.

From these two values you can work out what you ask.

For example:

Server app receives connection from 10.10.10.2 with client supplying 192.168.1.2

Server app receives connection from 10.10.10.3 with client supplying 192.168.1.3

The 'remote address' distinguishes the subnets.

So, all you need to figure out is how to extract the remote address of a client connection. If you are using any of the popular web technologies for your server app then this is very easy.

[浮城] 2024-09-06 00:44:13

一种方法是让各个客户端计算机使用广播消息来确定他们可以看到谁。让每个客户端侦听某个特定的 UDP 端口,并且每个客户端将其存在广播到本地广播域。当客户端能够以这种方式看到对方时,他们也可能可以相互建立 TCP 连接。

如果服务器需要知道哪些客户端可以相互通信,只需让客户端告诉服务器即可。

One approach is for the individual client machines to determine who they can see using a broadcast message. Have each client listen on some particular UDP port, and each client broadcast its presence to whatever the local broadcast domain is. When clients can see each other in this way, they can probably also make TCP connections to each other.

If the server needs to know which clients can talk to each other, just have the clients tell the server.

万水千山粽是情ミ 2024-09-06 00:44:13

如果网络图足够复杂,我想如果找到你需要的东西会非常困难。
您还应该考虑到 Comp1 可以与 Comp6 建立直接连接。

我可以建议的解决方案是探索。客户端从服务器接收所有其他客户端的列表,并尝试与每个客户端建立连接。我认为,假设网络中有任意数量的路由器/防火墙/NAT,这是了解哪些客户端真正可以访问的唯一方法。当然,对于大量计算机而言,规模不会太大。

If the network diagram is complicated enough I think if would be very difficuilt to find what you need.
You should also take into account that Comp1 can establish direct connection to Comp6.

The solution I can suggest is probing. Client receives list of all other clients from server and tries to establish connection to each of them. I think that would be the only way to know which clients are REALLY accessible assuming any number of routers/firewalls/NATs in the network. Doesn'r scale much for a big number of computers of course.

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