Reputation: 66607
My code is running on a server with multiple Ethernet ports which are physically wired to specific physical locations. Devices with known IPs are plugged in the other ends. I want to be able to detect if a device has changed place (in order to warn/scold the user). I.e, the difference between this:
Port X (192.168.33.1) ------------------ Device A (192.168.33.12)
Port Y (192.168.33.2) ------------------ Device B (192.168.33.13)
and this:
Port X (192.168.33.1) ------------------ Device B (192.168.33.13)
Port Y (192.168.33.2) ------------------ Device A (192.168.33.12)
I've considered putting the devices/ports on different subnets, but I would prefer to be able to say "you need to move device C to position N", rather than "I can't see anything!".
Disclaimer: I am not a networking expert
Upvotes: 0
Views: 107
Reputation: 239804
Presumably, you're actually talking to these devices in some way, shape or form, and sooner or later you'll have a Socket
object (either one you directly created or one that you can obtain from a higher level object such as TcpClient
's Client
property.
Once you've actually used the socket, you'll be able to query the LocalEndPoint
property and determine which local IP address you actually used to talk to the remote system:
The
LocalEndPoint
property is usually set after you make a call to theBind
method. If you allow the system to assign your socket's local IP address and port number, theLocalEndPoint
property will be set after the first I/O operation. For connection-oriented protocols, the first I/O operation would be a call to theConnect
orAccept
method. For connectionless protocols, the first I/O operation would be any of the send or receive calls.
Upvotes: 1