Programmatically Obtain a Computer's and Target's IP Address Using LabVIEW or LabWindows™/CVI

Updated Nov 28, 2018

Reported In

Hardware

  • CompactRIO Controller
  • CompactRIO Chassis

Software

  • LabVIEW Full
  • LabVIEW Base
  • LabWindows/CVI Base
  • LabWindows/CVI Full

Issue Details

How to programmatically read the IP address of my computer using LabVIEW or LabWindows™/CVI?
Additionally, How can I get the IP assigned to Target in LabVIEW?

Solution

LabVIEW​​​​

  • Use the String to IP function from the TCP palette.
  • To obtain all IP addresses of the computer, right-click the String to IP function and select Multiple Outputs. 
  • Using the String to IP functions, DHCP IPs assigned to Target can be obtained.
 

LabWindows™/CVI 

  • ​​Call the GetTCPHostAddr function.
  • To obtain all IP addresses of the computer, call GetALLTCPHstAddresses.
The following example shows how to implement this in LabWindpws™/CVI. This is accomplished by passing an address of a pointer to pointer to a char variable. The library allocates an array of strings which must be freed using the TCPFreeMemory function.
char ** addresses = NULL;
 int numAddresses;
 int index;

 GetAllTCPHostAddresses (&addresses, &numAddresses);
 /* Use the address strings... */
 for (index = 0; index < numAddresses; index++)
 {
 /* Free address string */
 TCPFreeMemory (addresses[index]);
 }
 /* Free addresses array */
 TCPFreeMemory (addresses);

Additional Information

To convert the IP addresses to dotted decimal notation or machine name, place an IP to String function on the block diagram. Wiring a true constant to the dot notation terminal will return the IP address in dot-notation format. Dot-notation format returns an IP address in the form 128.0.0.25. If the dot notation terminal is left unwired, or if a false constant is wired to it, it returns the IP address in the form machinename.domain.com.

WAS THIS ARTICLE HELPFUL?

Not Helpful