I'm going to do a test setup where I can't change IP-adresses of devices under test, but need a special orchestrator device to access all devices which can have the same ip adresses but are in different VLANs.
Lets say there are the following devices connected to a layer 3 switch:
Device under Test A, IP 192.168.1.1, VLAN10 Device under Test B, IP 192.168.1.2, VLAN10
Device under Test C, IP 192.168.1.1, VLAN20 Device under Test D, IP 192.168.1.2, VLAN20
Orchestrator Device, IP 192.168.1.3, VLAN10 + VLAN20 (tagged VLAN)
Now in C# I want to make a TCP connection to lets say Device A. This should in theorie be possible since the devices are separated on ethernet level and virtual NICs are created on the orchestrator device, but how can I tell my program which virtual NIC it should use when doing a connection?
One option would be to dynamically change the routing table on the orchestrator device (calling an external script or P/Invoke), but this is seems more like a workaround.
Antother option would be to just dynamcally enable / disable the virtual NICs, but I don't know if thats easily possible.
I'm using .NET Core btw.
The Problem:
C# is choosing the NIC based on the network you are using, and the subnet of those networks are the same you will need to use a workaround
The Solution:
Disable the NIC that you are not using in the Orchestrator Device using the cmd netsh command: netsh interface set interface "Interface-Name" disable
Send it to the cmd in C# using the System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
command.
This way you can switch between the devices!