Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
38 ratings:
 4.26 out of 5   

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

Primary Software:
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: LabWindows/CVI Development Systems>>LabWindows/CVI Full Development System

How do I programmatically read the IP address of my computer using LabVIEW or LabWindows™/CVI?

From LabVIEW:
The String to IP function, from the TCP palette, can be used to read the IP address of a computer. To do this, place a String to IP function on the block diagram. If the name terminal of the function is left unwired, net address returns the IP network address of the current machine.

To convert this to the machine name or to the standard dot format for IP addresses, place an IP to String function on the block diagram. Then,wire the output of the string to IP function to the net address terminal on the IP to String function. 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 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

To obtain all of the IP addresses of the computer, right-click the String to IP function and select Multiple Outputs, so that there is a check placed next to the option. The function will now output an array of IP addresses, so you must index the array in order to convert the IP address to a string using the IP to String function. The attached example uses an Index Array function, as can be seen in the figure below.

From LabWindows™/CVI
To find the IP address of a machine using LabWindows™/CVI, you can call the GetTCPHostAddr function. This function obtains the default IP address of the computer on which your program is currently running. To obtain all the IP addresses of the computer, call GetAllTCPHostAddresses. The following example shows how to implement this in LabWindows™/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);

Note: This is not supported in LabVIEW Real-Time.

Related Links:
KnowledgeBase 3ENE8DL2: Programmatically Converting a Hostname to an IP Address in LabVIEW
KnowledgeBase 3B6BTU4B: Return IP Address Instead of Machine Name in TCP and/or TCP Wait on

String to

Report Date: 06/08/2007
Last Updated: 08/15/2014
Document ID: 4A7G1N97

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit