02. Printing & Variables
Printing in Python¶
The print() function is one of the first things you’ll use in Python.
It is used to display output to the console (e.g., results of a scan, alerts, or logs).
Example:¶
This will output:
Cybersecurity Context:
Printing is used to show scan results, status messages, or alerts while running scripts.
Variables in Python¶
Variables are like containers that store data in your program.
They make it easy to reuse values (like IP addresses, ports, or credentials) without retyping.
Example:¶
# 02. Printing & Variables
ip_address = "192.168.1.10"
port = 22
service = "SSH"
print("Scanning Target:", ip_address)
print("Port:", port, "Service:", service)
Output:
Rules for Variables¶
-
Must start with a letter or
_(underscore). -
Can contain letters, numbers, and
_. -
Cannot start with a number.
-
Case-sensitive (
ipandIPare different).
Good:
Bad:
Cybersecurity Use Cases¶
- Storing Targets
- Port Information
- Credentials (for testing only – educational)
- Dynamic Output with f-strings
Output:
Quick Practice Tasks¶
-
Create a variable
attacker_ipand print it. -
Store a list of 3 ports (
22, 80, 443) and print them. -
Use f-string to print:
"Scanning <IP> on <Port>".
Note¶
Variables should not be hardcoded with real credentials in production scripts. For cybersecurity tools, store sensitive data securely (config files, environment variables).