Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ping Sweep help
#1
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.
Reply


Messages In This Thread
Ping Sweep help - by The501stOfNoobPy - Jun-25-2017, 02:33 PM
RE: Ping Sweep help - by Bass - Jun-25-2017, 02:44 PM
RE: Ping Sweep help - by The501stOfNoobPy - Jun-25-2017, 03:12 PM
RE: Ping Sweep help - by Bass - Jun-25-2017, 05:27 PM
RE: Ping Sweep help - by Larz60+ - Jun-25-2017, 06:17 PM
RE: Ping Sweep help - by DeaD_EyE - Jun-26-2017, 10:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some guidance on a script to ping a list of ip's cubangt 11 1,938 Aug-10-2023, 02:39 PM
Last Post: snippsat
  non-stop ping script kucingkembar 1 1,390 Aug-23-2022, 06:29 AM
Last Post: menator01
  Win32\ping.exe windows pops up -very annoying... tester_V 9 3,308 Aug-12-2021, 06:54 AM
Last Post: tester_V
  Looking for discord bot to make loop ping for address ip tinkode 0 1,848 Jul-26-2021, 03:51 PM
Last Post: tinkode
  Ping command using python 3.6.5 Martin2998 6 17,525 Apr-19-2021, 06:24 PM
Last Post: blazejwiecha
  GPIO high if network IP has good ping duckredbeard 3 2,390 Oct-12-2020, 10:41 PM
Last Post: bowlofred
  Create a program that PING a list of IPs skaailet 7 6,483 Mar-26-2020, 10:46 PM
Last Post: snippsat
  ping with output jacklee26 1 4,990 Nov-28-2019, 01:01 PM
Last Post: Axel_Erfurt
  PING PONG GAME akea 0 5,728 May-08-2019, 04:30 PM
Last Post: akea
  Ping Code Problem MTom5 1 2,782 Sep-04-2018, 09:58 PM
Last Post: MTom5

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020