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

Updated Dec 6, 2017

Reported In

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?

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. 
                                      

 

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