From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How select one Ethernet port on multiport network card ?

I have a network card with 4 Ethernet ports with IP1, IP2, IP3 and IP4. On each port I connect products which have a fixed and unchanged IP, this IP is the same for each product. So I have 4 different networks (IP1 <-> IP, IP2 <-> IP, IP3 <-> IP, IP4 <-> IP) and I must open a TCP communication with each product and the PC. I have used the VI TCP Open Connection but I can put anly the client IP and I don't put the host IP (IP, IP2, IP3 or IP4), so I don't know which product is. Which is code I can use to put the IP client and the IP host to create a TCP connection ?

Sorry for my poor english, thank for you answer,

0 Kudos
Message 1 of 7
(2,134 Views)

What OS are you using? Windows?

I suspect on Linux you could do this pretty easily using iptables - set up local port based routing rules in the OUTPUT table to force the interface.

On Windows, the same might be possible using "netsh", maybe "netsh interface", but I haven't found the appropriate rule/command yet...

 

Then you can wire the local port input to TCP Open Connection in LabVIEW, and have specific ports for each target device.

 

Alternatively, if the devices can respond to a UDP broadcast, you might be able to use the Create TCP Listener (4 times) and then broadcast a request for identification or something, and pick up 4 responses? The Create TCP Listener node has an input for "net address", which you can use as described here (Using Multiple Network Cards with LabVIEW) with the string -> IP conversion to specify the interface to listen on.


GCentral
0 Kudos
Message 2 of 7
(2,102 Views)

Without some NAT like infrastructure on the network card itself or in its driver I do not see how this could be made to work. I even doubt that iptables would be a valid solution, no matter how crazy network things you can make with them.

 

Someone between this network card and the device has to perform some network address translation as IP network routing does not allow for multiple devices having the same IP address on a network address range. And you can't assign different address ranges to each network port as the devices connected to it need to be in the address range of that network port. So something has to translate these devices network address to something else somehow, which is what NAT is for. This could be on the network adapter or if each network port is esposed to the OS as an individual controller also in the TCP/IP stack. However most multiport network adapters use an internal hub that provides a single network interface to the system and then you only can do this if the hub implementation itself allows for such an address translation.

And even if the hardware might be able to do it, it is a very big question if the OS driver even exposes that functionality. And if it does it can only be accessed by custom configuration tools since the standard driver interface does not provide such functionality.

 

Such a card, if it exists is likely very expensive.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 7
(2,070 Views)

I've seen a program that works like I asked and I didn't understand it, so I asked here too. The program I saw was C++ based, and that program worked without any problems, I think that set the IP address of the LAN Port to program.

Message 4 of 7
(2,035 Views)

Hard to say without seeing the actual C code. Most likely it binds the socket to the specific address of the network card.

LabVIEW does only allow to bind a listener to a specific address. For client connections should the interface to pass the data out through automatically be determinable by routing from the desired target address. Apparently your setup assumes that all 4 ports get assigned the same subnet range and the software selects the outgoing network port by binding the socket explicitly. This is a setup that is rather unusual and even surprising that it seems to work if it does! And a high chance to not work under different conditions such as different network adapters!

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 7
(2,020 Views)

There are several way of going about this but it all depends on what exactly you are trying to do. I have used all of these at various time on Windows 10.

 

Option 1.  If you do not require all the connections to be open at the same time.  You can disable all the ports and only enable them one at a time as required.

 

Option 2. If you are able to put all you attached devices on separate subnets. so for example 10.10.1.10 - 10.10.2.10  - 10.10.3.10 etc, in this situation you control this by the subnetmask on each port 222.222.0.0.

 

Option 3. Play around with the ARP, route and MAC addresses. Here you want to power on one connected device at a time and watch for its ARP message, the ARP shall provide you with the connected devices MAC address, you can then use this to add a specific route in you route table to that specific device. This can be tricky.

 

Option 4. Is a cheep version of Rolf's suggestion and Option 2 in the situation where you cannot do anything about the IP address of the connected devices. Buy a Raspberry Pie, for each device connected and give them all unique IP address and the write a very simple python script to map (port forward) and incoming messages out to the real IP address of your device.

 

Danny Thomson AshVire Ltd
0 Kudos
Message 6 of 7
(2,008 Views)

Been there done that

 

All you need is to learn how to use the "route" command line to set up the proper routing tables  since you basically have different networks on different ports. 

 

The routing tables setup by the route command will automatically send the proper IP addresses to the proper physical port 

 

route (at Microsoft Help Docs) Yes Windows 7-10 uses route too

(Windows and Linux "route" is very similar)

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 7
(1,998 Views)