Jun-25-2017, 02:33 PM
(This post was last modified: Jun-25-2017, 02:33 PM by The501stOfNoobPy.)
Hello all,
I'm currently learning Python while having while having to make use of it for a course. Would someone be able to help with explaining some parts of this Ping Sweep that I don't understand? I have some beginner level java programming experience from 6 years but I'm definitely rusty.
import subprocess
#I don't understand this command.
for ping in range(1,254):
#this defines a range of numbers for "ping". I think I have an understanding of this.
address = "10.11.1." + str(ping)
#creates the address variable with "10.11.1" in the first 3 octets
res = subprocess.call(['ping', '-c', '3', address])
#I only understand what's happening in the brackets and it's creating the res variable.
if res == 0:
print "ping to", address, "OK"
#The output if res = 0
elif res == 2:
print "no response from", address
#The output if res = 2, I take it you use "elif" if there are more than 2 possible outcomes?
else:
print "ping to", address, "failed!"
#The output if nothing matches the previous 2 outcomes.
I'm currently learning Python while having while having to make use of it for a course. Would someone be able to help with explaining some parts of this Ping Sweep that I don't understand? I have some beginner level java programming experience from 6 years but I'm definitely rusty.
import subprocess
#I don't understand this command.
for ping in range(1,254):
#this defines a range of numbers for "ping". I think I have an understanding of this.
address = "10.11.1." + str(ping)
#creates the address variable with "10.11.1" in the first 3 octets
res = subprocess.call(['ping', '-c', '3', address])
#I only understand what's happening in the brackets and it's creating the res variable.
if res == 0:
print "ping to", address, "OK"
#The output if res = 0
elif res == 2:
print "no response from", address
#The output if res = 2, I take it you use "elif" if there are more than 2 possible outcomes?
else:
print "ping to", address, "failed!"
#The output if nothing matches the previous 2 outcomes.