Skip to content

Commit 13a61f5

Browse files
committed
After supplying the first 3 octets it will scan the final range for available addresses
1 parent 788335b commit 13a61f5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

ping_subnet.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88

99
# Description : After supplying the first 3 octets it will scan the final range for available addresses
1010

11-
import os # Load the Library Module
12-
import subprocess # Load the Library Module
13-
import sys # Load the Library Module
11+
import os # Load the Library Module
12+
import subprocess # Load the Library Module
13+
import sys # Load the Library Module
1414

15-
filename = sys.argv[0] # Sets a variable for the script name
15+
filename = sys.argv[0] # Sets a variable for the script name
1616

1717
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: # Help Menu if called
1818
print '''
1919
You need to supply the first octets of the address Usage : ''' + filename + ''' 111.111.111 '''
2020
sys.exit(0)
2121
else:
2222

23-
if (len(sys.argv) < 2): # If no arguments are passed then display the help and instructions on how to run the script
23+
if (len(sys.argv) < 2): # If no arguments are passed then display the help and instructions on how to run the script
2424
sys.exit (' You need to supply the first octets of the address Usage : ' + filename + ' 111.111.111')
2525

26-
subnet = sys.argv[1] # Set the variable subnet as the three octets you pass it
26+
subnet = sys.argv[1] # Set the variable subnet as the three octets you pass it
2727

28-
if os.name == "posix": # Check the os, if it's linux then
29-
myping = "ping -c 2 " # This is the ping command
30-
elif os.name in ("nt", "dos", "ce"): # Check the os, if it's windows then
31-
myping = "ping -n 2 " # This is the ping command
28+
if os.name == "posix": # Check the os, if it's linux then
29+
myping = "ping -c 2 " # This is the ping command
30+
elif os.name in ("nt", "dos", "ce"): # Check the os, if it's windows then
31+
myping = "ping -n 2 " # This is the ping command
3232

33-
f = open('ping_'+subnet+'.log', 'w') # Open a logfile
34-
for ip in range(2,255): # Set the ip variable for the range of numbers
33+
f = open('ping_'+subnet+'.log', 'w') # Open a logfile
34+
for ip in range(2,255): # Set the ip variable for the range of numbers
3535
ret = subprocess.call(myping + str(subnet)+"."+str(ip) , shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the command pinging the servers
36-
if ret == 0: # Depending on the response
37-
f.write (subnet+"."+str(ip) + " is alive" + "\n") # Write out that you can receive a reponse
36+
if ret == 0: # Depending on the response
37+
f.write (subnet+"."+str(ip) + " is alive" + "\n") # Write out that you can receive a reponse
3838
else:
39-
f.write (subnet+"."+str(ip) + " did not respond" + "\n") # Write out you can't reach the box
39+
f.write (subnet+"."+str(ip) + " did not respond" + "\n") # Write out you can't reach the box

0 commit comments

Comments
 (0)