Help with scripting

I work for a MSP and we have lots of clients that have different internal IP addressing some 192.168.1. , 192.168.16. , and 10.1.1.  I'm trying to find a way that you can ping the Default Gateway, DNS Server and DHCP from command line without knowing the IP address of the object beforehand. Trying to set this up to help connectivity troubleshooting with non-technical users so they'd have to click on a .bat icon instead of trying to spend time trying to get them to run CMD commands over the phone. During my scouring online I did find this .bat that works for finding the default gateway. I have no idea how to modify it to output the DNS Server or DHCP.

@Set title=Pinging the Default Gateway...
@(color 6A) & (@Title %title%)
@echo please wait...

::# Define a temp variable 'DefaultGateway'
@For /f "tokens=3" %%* in (
   'route.exe print ^|findstr "\<\>"'
   ) Do @Set "DefaultGateway=%%*"

::# Redirect output to a textfile
@> "pinggateway.txt" (
  @echo [%Date% %time%] - %title%
  @ping %DefaultGateway%
@echo Done
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
stick an @ipconfig /all after @ping %DefaultGateway%
If the machines have PowerShell installed on them, you could do something like this.  Easier than trying to parse all the text output from other commands.
Rename ping1.txt to ping.bat or whatever.  Rename ping2.txt to ping.ps1.  Then with both files in the same folder, run the .bat file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
whuigensAuthor Commented:
With the method we're using to have users access this. There is no way to run .ps1. My only option is to use command prompt.
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

Users don't have to run the .PS1 file directly, they can just run the .BAT file like I mentioned.
whuigensAuthor Commented:
We use Continuum as a vendor to monitor our clients computers. They have a component to their agent that has an icon in the Notification area that clients can click on to do various troubleshooting steps. We can make customized versions of it but it only runs command prompt. I'd have to load the .bat file to the same location on every PC or make a separate communicator for each site with a custom network path to the .bat file. Not looking to spend that much time customizing it. Otherwise I'd just create a Communicator for each site and just do a ping command for each of their DNS and Gateway locations. Trying to find a command that will ping gateway and ping DNS without knowing the exact address. Trying to have one general command to use in one communicator customization. Otherwise I'd have to create 50-60 different Communicators, one per client site.
Ah, I see what you're getting at now.

Try this.  It's a single command.

Open in new window

To get to that
# In a PowerShell window
$command = 'Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "ipenabled = ''true''" | ForEach { "============"; "Pinging Default Gateway"; ping -n 1 $_.defaultipgateway; ""; "============"; "Pinging DNS servers"; $_.Dnsserversearchorder | ForEach { ping -n 1 $_ }; ""; "============"; "Pinging DHCP server"; ping -n 1 $_.dhcpserver}'
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
[Convert]::ToBase64String($bytes) | Out-File encoded.txt
# Open the "encoded.txt" file.  Copy the entire contents as the Base64 encoded command (should not have any line breaks or spaces).

# Run the encoded command in a command prompt as shown above.

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Network Management

From novice to tech pro — start learning today.