Example Code

Get MAC Address of Any Computer on Your Subnet

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview: This VI uses the system exec VI to issue the command line utilities "ping" and "arp" to obtain the MAC Address of the network interface from a different computer on your network.  Its functionality is limited to Windows systems.


Description: The arp utility only works for IP addresses on the same local subnet as the computer executing the VI.  Furthermore, it does not work for the IP address of the computer running the VI.  This utility attempts to use the ipconfig utility for Windows NT/2000/XP to get the MAC Address of the local computer, but if the local computer's IP Address is given, it will fail when run under Windows 9x or Windows ME.

This example VI shows how you can ping a computer just by knowing the IP address and be able to parse out the MAC address. The arg functions get the computer's information and returns the MAC address. Unfortunately, the arg function will NOT return the MAC address of the computer that runs the VI because the computer tries to use "ipconfig" instead of "ipconfig/all" which will not get the MAC address. This command is a strictly Windows OS specific so it will not work with other OS. This was saved in LabVIEW 8.2.1 so hopefully you can use it or gather what's going on by the screenshot.


Requirements: LabVIEW 2012 (or compatible). Hardware: network adapter.


Steps to Implement or Execute Code: Enter IP address in the string and run the VI. You will receive MAC address of the adapter. Be aware of multiple adapters.


Additional Information or References:

 

Programmatically setting range for multiple scales FP.png

Get MAC Address of Any Computer on Your Subnet sn.PNG


**This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Sinha
Member
Member
on

Thanks. It is useful for me