The Bat Script Journey — Start a Ping Command

Handhika Yanuar Pratama
Nerd For Tech
Published in
3 min readJan 25, 2024

--

Photo by Jefferson Santos on Unsplash

Bat, commonly known as Batch commands, is a scripting language primarily used in the Windows environment. If you’re reading this, chances are you’re using Windows. Have you ever delved deep into this programming language?

This script was very popular a decade ago — looking cool and making anyone who knew it appear like a hacker or at least a computer geek.

However, times have changed. Batch scripting is no longer as familiar, with many turning to languages like Python for hacking purposes. For me, there’s something beautiful about learning the classics, and the best part is sharing that knowledge.

This series, titled “The Bat Script Journey,” will explore batch scripts. Today, let’s start with something simple — implementing a ping command.

The Start

The ping command is commonly used to test internet connections. With a Bat script, we can execute the ping command more efficiently without having to open the CMD and manually input the command.

It’s an innovation, but it has become somewhat rare due to a lack of tutorials on the internet. Let’s hope this marks an excellent beginning.

The Tools

Unlike most programming languages that require an interpreter, Batch scripts, native to Windows, only need a Windows system and a Notepad. I believe you already have both.

The Command

Normally, we manually write a ping command like this:

ping 8.8.8.8 -n 5

Since we’re on Windows, I’ve added the -n 5 parameter to ensure the command runs only five times — no more, no less.

To connect this with a batch file, open Notepad or your preferred text editor and type:

start cmd /k “ping 8.8.8.8 -n 5"

The command is readable, isn’t it? The start means initiating the command, and cmd signifies we’re starting a CMD. What about /k?

After some literature review, /k stands for keep — it keeps the CMD output visible after execution. Save it as a .bat file, and it will look like this.

As it’s a batch file, double-click it, and the script will run, pinging the 8.8.8.8 server five times.

ALERT

An important note: I encountered a forever loop while running a batch file. The forever loop happened because I named the file ping.bat and called the ping command within it.

Bat is a CMD program that reads files based on their names. Since ping is already a built-in Windows program, creating a file named ping.bat will make the program think you’re running it indefinitely.

It could become a disaster for your computer🤣.

Conclusions

After reading this, I hope you’ve learned the very basics of valuable and simple batch programming — a script that runs a ping command with just one click. The article also provides an alert to ensure your program won’t inadvertently harm your computer.

If you’re considering continuing your journey into batch programming, consider following me. Thanks for reading.

Last but not least,
this is for educational purposes only.

--

--