How to make a batch file to ping an IP address in Windows


This works on Windows 10 Home.

  • Open Notepad or any text editor
  • Write the following code
  1. ping google.com 
  2. pause 
  • You can use any domain name or IP address instead of ‘google.com’
  • Save the file as filename.bat (replace filename with ‘ping’ or whatever you want)
  • Right click on the file and select ‘Run as administrator’. If you don’t execute the file as administrator, it would run forever and you wont get any result.

You can avoid this last step, by following these next steps once.

  • Right click on the file and select ‘Create shortcut’
  • Right click on the shortcut and select ‘Properties’
  • Click on ‘Shortcuts’ tab
  • Click on ‘Advanced…’ button
  • Tick mark ‘Run as administrator’
  • Click OK.
  • Now every time you double click shortcut, it will run as admin.

If you want to ping more than one domain, just add ‘ping’

  1. ping google.com 
  2. ping bing.com 
  3. pause 

You can add pause in between pings if you want to see results.

Or you can make the code to write result into a file.

  1. ping google.com >> C:pingresult.txt 
  2. ping bing.com >> C:pingresult.txt 

No need of ‘pause’.

Change the folder path as you wish.

If you ping on a daily basis, this might be helpful;

  1. echo. >> C:pingresult.txt 
  2. echo %DATE% %TIME% >> C:pingresult.txt 
  3. ping google.com >> C:pingresult.txt 

Every time you run the code, ping result would be added to the file ‘pingresult’ with date. First line adds a new line after the content already in the file.