11# Script Name : ping_subnet.py
22# Author : Craig Richards
33# Created : 12th January 2012
4- # Last Modified :
4+ # Last Modified :
55# Version : 1.0
66
7- # Modifications :
7+ # Modifications :
88
99# Description : After supplying the first 3 octets it will scan the final range for available addresses
1010
1111import os # Load the Library Module
12- import subprocess # Load the Library Module
12+ import subprocess # Load the Library Module
1313import sys # Load the Library Module
1414
1515filename = sys .argv [0 ] # Sets a variable for the script name
3030 elif os .name in ("nt" , "dos" , "ce" ): # Check the os, if it's windows then
3131 myping = "ping -n 2 " # This is the ping command
3232
33- f = open ('ping_' + subnet + '.log' , 'w' ) # Open a logfile
33+ f = open ('ping_' + subnet + '.log' , 'w' ) # Open a logfile
3434 for ip in range (2 ,255 ): # Set the ip variable for the range of numbers
35- ret = subprocess .call (myping + str (subnet )+ "." + str (ip ) , shell = True ,stdout = f ,stderr = subprocess .STDOUT ) # Run the command pinging the servers
35+ ret = subprocess .call (myping + str (subnet ) + "." + str (ip ) ,
36+ shell = True , stdout = f , stderr = subprocess .STDOUT ) # Run the command pinging the servers
3637 if ret == 0 : # Depending on the response
37- f .write (subnet + "." + str (ip ) + " is alive" + "\n " ) # Write out that you can receive a reponse
38+ f .write (subnet + "." + str (ip ) + " is alive" + "\n " ) # Write out that you can receive a reponse
3839 else :
39- f .write (subnet + "." + str (ip ) + " did not respond" + "\n " ) # Write out you can't reach the box
40+ f .write (subnet + "." + str (ip ) + " did not respond" + "\n " ) # Write out you can't reach the box
0 commit comments