Solved

Script or command to ping active nic gateway

Posted on 2014-11-10
3
153 Views
Last Modified: 2014-11-10
I have an application that displays a system tray icon that can reference a command or a script for troubleshooting steps for end users. Pinging the default gateway is a step I would like to add without customizing each application installation for each clients network. Any ideas?
0
Comment
Question by:emconsulting
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40433321
Something simple:
@echo off
setlocal EnableDelayedExpansion
set IP=
FOR /F "tokens=2 delims=:" %%a IN ('ipconfig ^| findstr /IC:"Default Gateway"') DO (
  if NOT "%%a" == " " ping %%a -n 1
)
exit /b

Open in new window

0
 

Author Comment

by:emconsulting
ID: 40433347
Thank you. I need the results do display to the user. What would I add to the code? I also saved this as a .bat file, is that correct?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40433364
.bat or .cmd does not matter, though I prefer latter.
You probably just need the script to pause until a key is pressed to allow for viewing the result. Replace the exit /b with pause.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief overview to explain gateways, default gateways and static routes OR NO - you CANNOT have two default gateways on the same server, PC or other Windows-based network device. In simple terms a gateway is formed when a computer such as a serv…
Resolve DNS query failed errors for Exchange
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question