Python Programming

Terminal Guide & Documentation

Python Programming

1. Introduction & Use Cases

Python is a high-level, interpreted programming language known for its readability and versatility. In the context of Termux, Python is the go-to language for automation, security auditing, and data analysis.

  • Cybersecurity: Writing exploit scripts, network scanners, and OSINT tools.
  • Automation: Scripting repetitive tasks within the Android environment.
  • Web Development: Running lightweight servers like Flask or Django.
  • Data Science: Performing complex calculations and data visualization.

2. Basic Syntax & Variables

Python uses clean, indentation-based syntax. To install Python in Termux, use pkg install python.

bash — variables.py
# Basic variable assignment
name = "Termux Hub"
version = 3.11
is_mobile = True

print(f"Welcome to {name}")
print(f"Current Version: {version}")

3. Control Flow & Functions

Managing logic and reusable code blocks in Python.

bash — logic.py
def check_access(level):
    if level >= 10:
        return "Root Access Granted"
    else:
        return "User Access Restricted"

for i in range(3):
    print(f"Attempt {i+1}: {check_access(i*5)}")

4. Core Commands Cheat-sheet

  • python script.py - Execute a Python script.
  • pip install [package] - Install third-party libraries.
  • python -m http.server 8080 - Start a quick web server.
  • len(obj) - Get the length of a list or string.
  • type(obj) - Check the data type of an object.

5. Popular Libraries & Frameworks

  • Requests: The standard for making HTTP requests.
  • Scrapy/BeautifulSoup: For web scraping and parsing HTML.
  • Pandas/NumPy: For data manipulation and math.
  • Flask/FastAPI: Modern web frameworks.
  • Scapy: Powerful packet manipulation for security testing.

6. Advanced Practical Example: Web Scraper

A simple script to fetch the title of a website using the requests and BeautifulSoup libraries.

bash — scraper.py
import requests
from bs4 import BeautifulSoup

def get_title(url):
    try:
        response = requests.get(url)
        soup = BeautifulSoup(response.text, 'html.parser')
        return soup.title.string
    except Exception as e:
        return str(e)

print(get_title("https://example.com"))

Explore More Tools

JavaScript

Build interactive web tools and automate with Node.js.

C++

Develop high-performance system tools and exploits.

Nmap

Network discovery and security auditing.

Explore Termux Hub

Kali Toolkit

Toolkit home (145 scripts) Foundations Network recon Defensive monitoring Vulnerability scanning Enumeration System hardening

Termux tool guides

Apache Brutus Cloudflare Cool Commands Cpp Findomain Fsociety Geo Recon Ghost Eye Hacktronian Ipicker Javascript John Local Server Manjaro Naabu Ncat Nmap Nordvpn Onex Pydictor Python Quasar Recondog Subfinder Termux Banner Ubuntu Gui Wafw00F Web Recon

Learn

Home Termux cheatsheet Python JavaScript C++ Cool Termux commands About Termux Hub