开发者

Identify machines behind a router uniquely based on ipaddress

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.

Identify machines behind a router uniquely based on ipaddress

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 chang开发者_StackOverflowe in my client or in my server, so that I can support this scenario. These two are the only things in my control.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜