Example Code

Native LabVIEW Host or IP Ping Using LabVIEW

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 allows you to ping a host and pass parameters to define the number of attempts and timeout.

 
Description

Have you ever looked to ping a target from your application? LabVIEW does not seem to have a built-in ping function. Using the System Exec VI can take a long time for the result to come back if the host or IP is unreachable. I'm sure a lot of us have wondered which port would be best to choose for a quick TCP Open and then Close it after checking for errors - but that's not really a "nice" way to do it. What's the solution? Well, we can add parameters to the command that we send to the System Exec VI. Using this VI, we can set the number of attempts and specify a timeout.

Use this VI directly, or use it as a sub VI. Modify it if needed.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Input the IP address into the 'host' Control.
  2. Specify the count and timeout, the default timeout is set to 1000 ms.
  3. Run the VI.

Additional Information or References
VI Snippet

007.png

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

Regards,


Imtiaz Chowdhury
Project Manager
Green Running / Austin Consultants

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

Comments
Ola_A
Member
Member
on

This really helped me make a simple computer/network checker, a list of ip-adresses is pinged every 10 mins and give a quick info on network status.

alpha1
Active Participant
Active Participant
on

Glad to hear that! Perhaps you could upload your modified application as well with a link?

Regards,


Imtiaz Chowdhury
Project Manager
Green Running / Austin Consultants

Brad
Active Participant
Active Participant
on

Anyone know if there is a way to Ping from both Windows (as shown here) or from RT (The system Exec doesn't work on RT for the PING command).

maximint
Member
Member
on

the first Labview ping vi I found, which is working well

thanks-

carlos_camargo
Member
Member
on

Thanks very much, this was quite helpful to me as well, so I gave you a Kudos!

SergeS
Member
Member
on

Be carefull, approach below may give you fake positive result. I've got this situation on my Win10 PC with Mikrotik router, when host was connected and later disconnected, ping sometimes returned code as zero, but std output tells "host is unreachable". That is why to look only at returned code is not really reliable solution, better to analyze std output string.

007.png

 

Below is my solution. I am not very good in regular expressions, so I believe parsing could be easily improved. Another thing to improve - make compatible with different formats of ping output string. Please share your version of improvements 🙂

Ping_CLI.png

SergeS
Member
Member
on

Still not perfect :-), ping may report % lost less than 100% but all packets are actually lost, see screenshot againCapture.PNG:

So, my parsing will return not actual statistics. Here is simple fix:

Ping_CLI.png

 

nibuddy1777
Member
Member
on

For an abbreviated version that will work on either linux or Windows.  This is simply looking for the average round trip and will also look at other errors and give a simple connected or not connected flag.  NOTE: if you put a malformed name (not IP address), the DNS resolution time is not taken into account so it may take longer than your expected timeout.

 

 

Ping_CLI_Linux_or_Win.png