LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

STR to IP --- Which result?

LV 2018 SP1..    

Consider this:

STR 2 IP.png

 

I want to display for the user, the IP address he should use to connect his instrument to the host CPU.

If I use the single-result mode, I get the IP number for something else (I have VMWare Workstation installed, but not running, when this screenshot was taken).

 

What I want is the "1.30" result (in this case).

 

What are the rules here?  What order do these come back in?

I don't know if it will always be a "192.168.1.xxx" subnet or not.

Can I always use the LAST one in the array returned?

 

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 23
(2,962 Views)

In this case I would probably run Ipconfig with the Systemexec.vi saving the output and parse the string.

 

Probably look for "Ethernet Adapter Ethernet:" and go from there.

 

ipcCapture.PNG

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 23
(2,920 Views)

I've used this on several occasions without any ambiguity, but realized that I was "asking the reverse question" -- I was running this from the PC and asking it about "devices that could be detected".  Yes, there can be several devices out there (in particular, I'm currently "detecting" a myRIO, but if I go into MAX and look at "Remote Systems", I can find several myRIOs and a few other things (an sbRIO, for example).  So my code looks at how many IPs were returned -- if 0, I tell the User that there's "no There there", if 1 I just connect, and if >1, I populate a ComboBox that shows me the IPs and names of the Devices and lets me choose which one to use.  Here's a Snippet (since not even I am seriously using LabVIEW 2021 yet).  The sub-VI "Choose" is a Dialog box that shows the Message "Choose Target" and populates a ListBox with the "Choices" returned by the System request, returning the single Choice the User selected.

 

Target ID, IP.png

 

Bob Schor

0 Kudos
Message 3 of 23
(2,911 Views)

Depending on the required reliability, I would recommend to avoid parsing the ipconfig output. Windows provides plenty of tools to report the network configuration that are more suitable to machine consumption and can be made to report precisely the interface You are looking for. See, for example, netsh or, if you want to skip parsing altogether, the System.Net namespace

0 Kudos
Message 4 of 23
(2,895 Views)

There is no trivial way to do that not even with parsing multiple command line tool outputs. Nowadays computers can have many different network adapters active at the same time. That can be virtual network adapters such as for your VmWare, built in adapters, WIFI adapters and adapters through docking stations, but even a USB port can be seen as an actual network adapter if the according device connected has a USB-LAN device class.

 

On my computer the String to IP node in array mode returns typically 6 or more IP addresses. So on such a computer your simple logic of trying to enumerate all IP addresses and eliminating things like VmWare will not work. And for the rest you can not rely on the name of physical network adapters, they can easily be renamed by the user.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 23
(2,887 Views)

It looks like even LabVIEW itself gets it wrong: The *.ALIASES file for the project lists "My Computer" as "192.168.6.1"

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 23
(2,866 Views)

Technically it is not wrong. That IP address is a valid address for your computer. That it is only useful when you want to talk from one of the VmWare instances configured to use VMNet8 (by default the NAT mode) to your host computer is simply a technical detail. 😁

 

The problem here is simply that the String to IP function uses the Winsock library to get the valid IP addresses. And Winsock seems to consider your VMNet8 address as the default address and therefore returns it as the first one. 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 7 of 23
(2,857 Views)

I am not a networking expert (The more I find out about networking, the more I realize I don't know anything) and not even sure if this what you are looking for, but here is something I did a while ago that seemed to work for my needs. It lists all "real" IP address on your PC (ignoring the virtual ones)

List NIC IP Addy.png

 

Frozen_0-1637763369310.png

 

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 8 of 23
(2,853 Views)

Rolf, are you a lawyer by any chance?  😂

 

It's wrong for my purposes, at least.  I cannot dial into 192.168.6.1 from outside the box and connect to a LabVIEW listener. That's not even on the same subnet.

 

If I use RESOLVE MACHINE ALIAS with an argument of "My Computer", it comes back with "localhost".  (Not 192.168.6.1 as the ALIASES file has it).  Not helpful.

 

If I set up a listener and wait on a connection, while connecting from another thread, the remote address comes in as "localhost", or "127.0.0.1"  Not helpful.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 9 of 23
(2,852 Views)

It lists all "real" IP address on your PC (ignoring the virtual ones)

 

Frozen, I'm not sure how that helps.  In my case it lists:

192.168.1.30

192.168.8.1

192.168.6.1

 

That's exactly the same as STR-IP (multiple) but in the reverse order.  I'm not sure I can depend on the one I want being first.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 23
(2,849 Views)