From 9fb79f649f954a1e66d1e0d48adee1178e1151fc Mon Sep 17 00:00:00 2001 From: Qathula Date: Sun, 7 Jul 2024 11:12:54 -0400 Subject: [PATCH 01/23] Added Apples --- ShoppingList.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ShoppingList.txt b/ShoppingList.txt index 27409dd..5349b6e 100644 --- a/ShoppingList.txt +++ b/ShoppingList.txt @@ -2,4 +2,5 @@ Milk Break Bananas Eggs - +Apples +Tomatoes From 2d789844fba5a47607261197120e532e62f3ae1b Mon Sep 17 00:00:00 2001 From: Qathula Date: Sun, 7 Jul 2024 11:31:19 -0400 Subject: [PATCH 02/23] Added Cake --- ShoppingList.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ShoppingList.txt b/ShoppingList.txt index 5349b6e..57cfe2e 100644 --- a/ShoppingList.txt +++ b/ShoppingList.txt @@ -4,3 +4,4 @@ Bananas Eggs Apples Tomatoes +Cake \ No newline at end of file From 7069ae2fd435b957fb7dc54fc8fb0ef83a2ddedb Mon Sep 17 00:00:00 2001 From: Qathula Date: Sun, 7 Jul 2024 12:37:38 -0400 Subject: [PATCH 03/23] HelloWorld1.py --- start/CH02/HelloWorld1.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 start/CH02/HelloWorld1.py diff --git a/start/CH02/HelloWorld1.py b/start/CH02/HelloWorld1.py new file mode 100644 index 0000000..e69de29 From 6788b47fed0ff2a098f30a3a92cdc856a27084ca Mon Sep 17 00:00:00 2001 From: Qathula Date: Mon, 8 Jul 2024 14:18:44 -0400 Subject: [PATCH 04/23] HelloWorld2.py --- start/CH02/HelloWorld2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/start/CH02/HelloWorld2.py b/start/CH02/HelloWorld2.py index 1072d14..25fc9ad 100755 --- a/start/CH02/HelloWorld2.py +++ b/start/CH02/HelloWorld2.py @@ -2,6 +2,6 @@ # A simple "Hello World" script in python with Inputs # Created -# Suggestion, build out 1 line at a time -# Once multiple print statemetns exist, put a breakpoint at first print line -# Then walk through as an example of "debugging" +# your_name = input("wtat is your name? ") +# print("Hello {0}" format(your_name)) + From 44a2e354e150ae59be8fe3be7cbcc36b9cb5dda4 Mon Sep 17 00:00:00 2001 From: Qathula Date: Mon, 8 Jul 2024 15:21:01 -0400 Subject: [PATCH 05/23] HelloWorld10.py --- start/CH02/HelloWorld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start/CH02/HelloWorld.py b/start/CH02/HelloWorld.py index 88eb615..67081de 100755 --- a/start/CH02/HelloWorld.py +++ b/start/CH02/HelloWorld.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 # A simple "Hello World" script in python -# Created \ No newline at end of file +# Created by Quentin Athula 7/8/2024 \ No newline at end of file From 972c9990bea07b54bff6171d6e9bb086afcbc313 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 8 Mar 2025 18:37:47 -0500 Subject: [PATCH 06/23] Commit this two changes! --- end/CH02/HelloWorld.py | 6 ++++-- end/CH02/HelloWorld2.py | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/end/CH02/HelloWorld.py b/end/CH02/HelloWorld.py index 205893c..5b04873 100755 --- a/end/CH02/HelloWorld.py +++ b/end/CH02/HelloWorld.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 # A simple "Hello World" script in python -# Created by Ed Goad, 2/3/2021 -print("Hello World") \ No newline at end of file +# Created by Quentin Athula, 3/8/2025 + +your_name = input("what is your name? ") +print("Gwy {0}".format(your_name)) diff --git a/end/CH02/HelloWorld2.py b/end/CH02/HelloWorld2.py index 0dccc6c..1213c85 100755 --- a/end/CH02/HelloWorld2.py +++ b/end/CH02/HelloWorld2.py @@ -1,6 +1,11 @@ #!/usr/bin/env python3 # A simple "Hello World" script in python with Inputs -# Created by Ed Goad, 2/3/2021 +# Created by Quentin Athula, 3/8/2025 your_name = input("What is your name? ") print("Hello {0}".format(your_name)) +print(f"Hello {your_name}") +print("Hello " + your_name) +print("Hello", your_name) +message = "Hello" + " " + your_name +print(message) From 29c8446ea1345761261aa3dc143ccc0782faf0a2 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 8 Mar 2025 18:44:06 -0500 Subject: [PATCH 07/23] Commit Genny changes! --- end/CH02/HelloWorld2.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/end/CH02/HelloWorld2.py b/end/CH02/HelloWorld2.py index 1213c85..0fd1452 100755 --- a/end/CH02/HelloWorld2.py +++ b/end/CH02/HelloWorld2.py @@ -3,9 +3,9 @@ # Created by Quentin Athula, 3/8/2025 your_name = input("What is your name? ") -print("Hello {0}".format(your_name)) -print(f"Hello {your_name}") -print("Hello " + your_name) -print("Hello", your_name) -message = "Hello" + " " + your_name +print("Genny {0}".format(your_name)) +print(f"Genny {your_name}") +print("Genny " + your_name) +print("Genny", your_name) +message = "Genny" + " " + your_name print(message) From aa1c8d3c140f42bee9155b58b2b49e660aef4cb0 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 8 Mar 2025 21:21:47 -0500 Subject: [PATCH 08/23] Commit this changes again! --- end/CH02/HelloWorld.py | 2 +- end/CH02/HelloWorld2.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/end/CH02/HelloWorld.py b/end/CH02/HelloWorld.py index 5b04873..f33fdce 100755 --- a/end/CH02/HelloWorld.py +++ b/end/CH02/HelloWorld.py @@ -3,4 +3,4 @@ # Created by Quentin Athula, 3/8/2025 your_name = input("what is your name? ") -print("Gwy {0}".format(your_name)) +print("Hello {0}".format(your_name)) diff --git a/end/CH02/HelloWorld2.py b/end/CH02/HelloWorld2.py index 0fd1452..1213c85 100755 --- a/end/CH02/HelloWorld2.py +++ b/end/CH02/HelloWorld2.py @@ -3,9 +3,9 @@ # Created by Quentin Athula, 3/8/2025 your_name = input("What is your name? ") -print("Genny {0}".format(your_name)) -print(f"Genny {your_name}") -print("Genny " + your_name) -print("Genny", your_name) -message = "Genny" + " " + your_name +print("Hello {0}".format(your_name)) +print(f"Hello {your_name}") +print("Hello " + your_name) +print("Hello", your_name) +message = "Hello" + " " + your_name print(message) From 7773b06ed133b87f49061bad4df81ab7b3e4d4b1 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sun, 9 Mar 2025 14:08:08 -0400 Subject: [PATCH 09/23] Commit simplecalculatoy.py --- end/CH02/SimpleCalculator.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/end/CH02/SimpleCalculator.py b/end/CH02/SimpleCalculator.py index 4580dc3..2d1380a 100755 --- a/end/CH02/SimpleCalculator.py +++ b/end/CH02/SimpleCalculator.py @@ -1,14 +1,14 @@ -#!/usr/bin/env python3 -# A simple calculator to show math and conditionals -# Created by Ed Goad, 2/3/2021 +#!/user/bin/env python3 +# A simple calculator script in python +# Created by Quentin Athula, 3/9/2025 -# Get inputs first -# Note we are casting the numbers as "float", we could also do "int" +# Get input from the user +# Note we are casting the numbers as "float", we could also cast them as "int" first_num = float(input("What is the first number: ")) activity = input("What activity? ( + - * / ) ") second_num = float(input("What is the second number: ")) -# depending on the selected activity, perform an action +# depending on the selected activity, perform the calculation if activity == "+": print(first_num + second_num) if activity == "-": @@ -17,3 +17,4 @@ print(first_num * second_num) if activity == "/": print(first_num / second_num) + From f3dc9889891272fe68291ed70752d6b4320d68c9 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 15 Mar 2025 20:39:43 -0400 Subject: [PATCH 10/23] Commit simplepinger1.py --- end/CH03/pinger1.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/end/CH03/pinger1.py b/end/CH03/pinger1.py index a21dab0..cbc514b 100755 --- a/end/CH03/pinger1.py +++ b/end/CH03/pinger1.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python3 +#!/usr/bin/venv python3 # First example of pinging from Python -# By Ed Goad -# 2/27/2021 +# By Quentin Athula +# 3/15/2025 # import necessary Python modules import platform From 28cf44552c449626e32f71602ca3e1148de88b27 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 15 Mar 2025 21:34:46 -0400 Subject: [PATCH 11/23] Commit simplepinger2.py --- end/CH03/pinger2.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/end/CH03/pinger2.py b/end/CH03/pinger2.py index 17f4eed..6706f0e 100755 --- a/end/CH03/pinger2.py +++ b/end/CH03/pinger2.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python3 +#!/usr/bin/venv python3 # Second example of pinging from Python -# By Ed Goad -# 2/27/2021 +# By Quentin Athula +# 3/15/2025 # import necessary Python modules import platform @@ -9,9 +9,9 @@ # Assign IP to ping to a variable ip = "127.0.0.1" -# Determine the currrent OS -currrent_os = platform.system().lower() -if currrent_os == "windows": +# Determine the current OS +current_os = platform.system().lower() +if current_os == "windows": # Build our ping command for Windows ping_cmd = f"ping -n 1 -w 2 {ip} > nul" else: From 4a440cc161d98e8089a15cbe50a9c4a56bbf33c3 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 15 Mar 2025 23:14:10 -0400 Subject: [PATCH 12/23] Commit for simple darwin pinger2.py --- end/CH03/pinger2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/end/CH03/pinger2.py b/end/CH03/pinger2.py index 6706f0e..f16d0b5 100755 --- a/end/CH03/pinger2.py +++ b/end/CH03/pinger2.py @@ -11,9 +11,9 @@ ip = "127.0.0.1" # Determine the current OS current_os = platform.system().lower() -if current_os == "windows": - # Build our ping command for Windows - ping_cmd = f"ping -n 1 -w 2 {ip} > nul" +if current_os == "darwin": + # Build our ping command for darwin + ping_cmd = f"ping -n 1 -w 2 {ip} > /dev/null 2>&1" else: # Build our ping command for other OSs ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" From 64cd6af9a576625274bf4ede55a64bdf21019185 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sun, 16 Mar 2025 19:17:31 -0400 Subject: [PATCH 13/23] Commit for simple pinger3.py for windows --- end/CH03/pinger3.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/end/CH03/pinger3.py b/end/CH03/pinger3.py index 4f4d141..60e18e9 100755 --- a/end/CH03/pinger3.py +++ b/end/CH03/pinger3.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # Third example of pinging from Python -# By Ed Goad -# 2/27/2021 +# By Quentin Athula +# 3/16/2025 # import necessary Python modules import platform @@ -9,14 +9,14 @@ # Define the prefix to begin pinging ip_prefix = "192.168.0." -# Determine the currrent OS -currrent_os = platform.system().lower() +# Determine the current OS +current_os = platform.system().lower() # Loop from 0 - 254 for final_octet in range(254): # Assign IP to ping to a variable # Adding 1 to final_octet because loop starts at 0 ip = ip_prefix + str(final_octet + 1) - if currrent_os == "windows": + if current_os == "windows": # Build our ping command for Windows ping_cmd = f"ping -n 1 -w 2 {ip} > nul" else: From 3915ce7288e92f6f5cd2640b4d42262a7a9f4c05 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sun, 16 Mar 2025 20:12:23 -0400 Subject: [PATCH 14/23] Commit for simple pinger.py for new branch --- .idea/.gitignore | 3 +++ .idea/PythonforCybersecurity-example.iml | 8 ++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 6 files changed, 38 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/PythonforCybersecurity-example.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/PythonforCybersecurity-example.iml b/.idea/PythonforCybersecurity-example.iml new file mode 100644 index 0000000..d859cb1 --- /dev/null +++ b/.idea/PythonforCybersecurity-example.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3383e26 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2e2bf2c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 45e5a249e05f91a94eb20720eeb197ed2d5eacac Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sun, 16 Mar 2025 21:12:43 -0400 Subject: [PATCH 15/23] This is first Commit for Hello World! --- start/CH02/HelloWorld.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/start/CH02/HelloWorld.py b/start/CH02/HelloWorld.py index 67081de..d39c824 100755 --- a/start/CH02/HelloWorld.py +++ b/start/CH02/HelloWorld.py @@ -1,3 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/.venv python3 # A simple "Hello World" script in python -# Created by Quentin Athula 7/8/2024 \ No newline at end of file +# Created by Quentin Athula 3/16/2025 +print("hello world") \ No newline at end of file From 8c39c586eb4e4e8f8dec51c6f78524bbd6d37286 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sun, 16 Mar 2025 21:12:43 -0400 Subject: [PATCH 16/23] This is first Commit for Hello World! --- start/CH02/HelloWorld.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/start/CH02/HelloWorld.py b/start/CH02/HelloWorld.py index 67081de..d39c824 100755 --- a/start/CH02/HelloWorld.py +++ b/start/CH02/HelloWorld.py @@ -1,3 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/.venv python3 # A simple "Hello World" script in python -# Created by Quentin Athula 7/8/2024 \ No newline at end of file +# Created by Quentin Athula 3/16/2025 +print("hello world") \ No newline at end of file From 120963cfb26048f8acf2fb6c7ac14c3f001fd8fe Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 22 Mar 2025 21:07:37 -0400 Subject: [PATCH 17/23] This is a sample to IDLE --- .idea/misc.xml | 2 +- start/CH02/HelloWorld1.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 3383e26..c063f29 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/start/CH02/HelloWorld1.py b/start/CH02/HelloWorld1.py index e69de29..532dd55 100644 --- a/start/CH02/HelloWorld1.py +++ b/start/CH02/HelloWorld1.py @@ -0,0 +1,4 @@ +#!/user/bin/.venv/ python3 +# A sample "Check that the IDLE is working" script in python +# Created by Quentin Athula 3/22/2025 +print("This is a sample to check that the IDE is working") \ No newline at end of file From f354b4328b8e8f7c1de478a9a1f9d96d8bbc57c9 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 22 Mar 2025 22:38:58 -0400 Subject: [PATCH 18/23] commit message what is your name? --- start/CH02/HelloWorld2.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/start/CH02/HelloWorld2.py b/start/CH02/HelloWorld2.py index 25fc9ad..cacc939 100755 --- a/start/CH02/HelloWorld2.py +++ b/start/CH02/HelloWorld2.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 # A simple "Hello World" script in python with Inputs -# Created +# Created by Quentin Athula 3/22/2025 + +your_name = input("What is your name? ") +print("Hello {0} ".format(your_name)) -# your_name = input("wtat is your name? ") -# print("Hello {0}" format(your_name)) From 0d5acd77b0f4b1df06eead853c8ec11787da90ba Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Sat, 22 Mar 2025 22:56:05 -0400 Subject: [PATCH 19/23] commit message what is your name2? --- start/CH02/HelloWorld3.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/start/CH02/HelloWorld3.py b/start/CH02/HelloWorld3.py index decd537..4b0b02f 100644 --- a/start/CH02/HelloWorld3.py +++ b/start/CH02/HelloWorld3.py @@ -1,3 +1,11 @@ #!/usr/bin/env python3 # A more complex "Hello World" script in python with Inputs -# Created +# Created by Quentin Athula 3/22/2025 + +your_name = input("What is your name? ") +print("Hello {0} ".format(your_name)) +print(f"Hello {your_name}") +print("Hello" + your_name) +print("Hello", your_name) +message = "Hello" + " " + your_name +print(message) From 2a02cbcd06333670fee4567e9559395d4e26141e Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Tue, 22 Apr 2025 12:11:20 -0400 Subject: [PATCH 20/23] First example of pinging from python! --- start/CH03/pinger1.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/start/CH03/pinger1.py b/start/CH03/pinger1.py index 6af65f6..d4e5ba9 100755 --- a/start/CH03/pinger1.py +++ b/start/CH03/pinger1.py @@ -1,3 +1,17 @@ #!/usr/bin/env python3 # First example of pinging from Python -# By \ No newline at end of file +# By Quentin Athula +# 4/22/2025 + +# import necessary python modules +import platform +import os + +# Assign IP address to ping to a variable +ip = "127.0.0.1" +# Build the command to ping the IP address +ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" +# Execute command and capture exit code +exit_code = os.system(ping_cmd) +# print the result to the console +print(exit_code) \ No newline at end of file From a0f366f4c8b1b9e4434db74b78620cefc130d507 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Tue, 22 Apr 2025 13:51:55 -0400 Subject: [PATCH 21/23] A second example of pinging from python! --- start/CH03/pinger2.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/start/CH03/pinger2.py b/start/CH03/pinger2.py index c80c993..eda325a 100755 --- a/start/CH03/pinger2.py +++ b/start/CH03/pinger2.py @@ -1,3 +1,24 @@ -#!/usr/bin/env python3 -# Second example of pinging from Python -# By \ No newline at end of file +#!/user/bin/.venv/ python3 +# A second example of pinging from python +# Created by Quentin athula +# 4/22/2025 + +# import necessary python modules +import platform +import os + +# Assign IP address to ping to a variable +ip = "127.0.0.1" +# Determine the current operating system +current_os = platform.system() . lower() +if current_os == "windows": + # Build our ping command for windows + ping_cmd = f"ping -n 1 -w 2 {ip} > nul" +else: + # Build our ping command for other operating systems + ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" + +# Execute command and capture exit code +exit_code = os.system(ping_cmd) +# print the result to the console +print(exit_code) \ No newline at end of file From c236248779c274ca3e782ffa472fd92d4670d00c Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Tue, 22 Apr 2025 14:42:01 -0400 Subject: [PATCH 22/23] A Third example of pinging from python! --- start/CH03/pinger3.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/start/CH03/pinger3.py b/start/CH03/pinger3.py index 8ca3629..618c7b3 100755 --- a/start/CH03/pinger3.py +++ b/start/CH03/pinger3.py @@ -1,3 +1,30 @@ -#!/usr/bin/env python3 +#!/user/bin/.vnv/ python3 # Third example of pinging from Python -# By \ No newline at end of file +# By Quentin Athula +# 4/22/2025 + +# import necessary python modules +import platform +import os + +# Define a function to ping an IP address +ip_prefix = "192.168.1." +# determine the current operating system +current_os = platform.system(). lower() +# Loop from 0 - 254 +for final_octet in range(254): + # Assign IP to ping to a variable + # Adding 1 to final_octet because loop starts at 0 + ip = ip_prefix + str(final_octet + 1) + if current_os == "windows": + # Build our ping command for windows + ping_cmd = f"ping -n 1 -w 2 {ip} > nul" + else: + # Build our ping command for other operating systems + ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" + + # Execute command and capture exit code + exit_code = os.system(ping_cmd) + # print results to console only if successful + if exit_code == 0: + print("{0} is online" .format(ip)) From a262ca6319850e0c04adcf2bf748ee957e0028b0 Mon Sep 17 00:00:00 2001 From: Quentin Athula Date: Tue, 22 Apr 2025 22:27:59 -0400 Subject: [PATCH 23/23] A Fourth example of pinging from python! --- start/CH03/pinger4.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/start/CH03/pinger4.py b/start/CH03/pinger4.py index 3d174a0..b622de8 100755 --- a/start/CH03/pinger4.py +++ b/start/CH03/pinger4.py @@ -1,3 +1,38 @@ #!/usr/bin/env python3 # Fourth example of pinging from Python -# By \ No newline at end of file +# By Quentin athula +# 4/22/2025 + +# import necessary python modules +import platform +import os + +def ping_host(ip): + # Determine the current operating system + current_os = platform.system().lower() + if current_os == "windows": + # Build our ping command for windows + ping_cmd = f"ping -n 1 -w 2 {ip} > nul" + else: + # Build our ping command for other operating systems + ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" + + # Execute command and capture exit code + exit_code = os.system(ping_cmd) + return exit_code + +# Define the prefix to begin pinging +ip_prefix = "192.168.1." + +# loop from 0 - 254 +for final_octet in range(254): + # Assign IP to ping to a variable + # Adding 1 to final_octet because loop starts at 0 + ip = ip_prefix + str(final_octet + 1) + + # call the ping_host function and capture the return value + exit_code = ping_host(ip) + + # print results to console only if successful + if exit_code == 0: + print("{0} is online" .format(ip))