Programmatically Obtain a Computer's IP Address Using LabVIEW or LabWindows™/CVIPrimary Software: Primary Software Version: 1.0 Primary Software Fixed Version: N/A Secondary Software: LabWindows/CVI Development Systems>>LabWindows/CVI Full Development System
Problem: How do I programmatically read the IP address of my computer using LabVIEW or LabWindows™/CVI? Solution: 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.
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 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.
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; 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 Listen.vi and/or TCP Wait on Listener.vi Attachments:
Report Date: 06/08/2007 Last Updated: 08/15/2014 Document ID: 4A7G1N97 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||



