Category filter

Script to Ping a Website on Windows

Ping is a command-line utility that checks if an IP address or host is accessible over a network connection. To check the accessibility of a website, the Ping command sends data packets to the target address and waits for the response. A successful ping is registered if the data packets are returned without damage. IT admins can remotely troubleshoot network connectivity issues on their endpoint devices using the Ping command. This document covers the custom script to remotely ping a website on a Windows device using Hexnode UEM.

Disclaimer:

The Sample Scripts provided below are adapted from third-party Open-Source sites.

Batch Script

Pass the website to be pinged as the argument.

For example: https://www.hexnode.com

  • echo off – To prevent displaying all commands in a batch file
  • Ping – This command initializes the website ping request.
  • –n – This flag is a count of the number of echo requests to send.
  • %1 – Represents the first argument passed by the admin, in this case, website URL or IP address.
  • TTL – Stands for Time to Live. Only if the packet’s time to live is greater than 0, the errorlevel is checked.
  • errorlevel – This command returns an integer. Any value other than 1 is considered a successful website ping, and the corresponding message is displayed.

PowerShell Script

Pass the website to be pinged as the argument.

For example: https://www.hexnode.com

  • $Hostname – Contains the website passed as the argument.
  • $ping – Initializes the ping request for the target website.
  • get-wmiobject – Gets the instances of Windows Management Instrumentation (WMI) classes or information about the available classes.
  • win32_pingstatus – Gives the values returned by the $ping command.
  • $ping.Statuscode – This returns an integer value. If the value is equal to 0, a success message is displayed. Any value other than 0 is considered an error.
  • $ping.responsetime – Displays the time taken by the website to respond.
Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository