Blog Archives

NetEng PyScript 1: Mass Ping

Python Scripts For Network Engineers 1: Mass Ping

 

import subprocess
import os
import sys

for ping in range(1,32): #(x,y) x = starting range; y = ending range but not including
address = sys.argv[1] + str(ping)
x = subprocess.call([‘ping’, ‘-c’, ’3′, ‘-W’, ’1′, address])
        if x == 0:
                printping to“, address, “OK
        elif x == 2:
                printno response from“, address
        else:
                printping to“, address, “failed!

 

Example:

python ping_script.py 172.16.1.0

Pings would then start from 172.16.1.1 up to 172.16.1.31

networking-link.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com.