Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Run the following command to install the requirements:
```bash
pip install -r requirements.txt
```

## 2. Find Your Network's Login URL and Payload
```
2.1 Connect to your WiFi network manually.
Expand All @@ -15,6 +16,7 @@ pip install -r requirements.txt
2.4 Find the POST request URL inside the Network tab(should look like http://192.168.x.x:8090/login.xml).
2.5 Copy the form data parameters (like username, password, a, etc.).
```

## 3. Edit ```wifi_auto_login.py``` file
Modify the ```def wifi_login()``` function to match your payload parameters.
i.e:
Expand Down Expand Up @@ -96,3 +98,28 @@ python wifi_auto_login.py

We have succesfully setup the script now the wifi or LAN will get connected **automatically on system startup**!

## **Command-Line Interface (CLI) Usage**

This script now includes a command-line interface for easier interaction. Here are the available options:

| Command | Description |
| ---------------------- | ----------------------------------------------------------- |
| `python wifi_auto_login.py --login` | Performs a login attempt. This is the default action. |
| `python wifi_auto_login.py --view-logs` | Shows the 5 most recent login attempts. |
| `python wifi_auto_login.py --view-logs 10` | Shows the specified number of recent login attempts. |
| `python wifi_auto_login.py --setup` | Launches an interactive wizard to guide you through setup. |
| `python wifi_auto_login.py --test` | Tests the connection to the login server without logging in. |
| `python wifi_auto_login.py --clear-logs` | Deletes all stored login logs from the database. |
| `python wifi_auto_login.py --help` | Displays the help menu with all available commands. |

### **Examples**

**To perform a login:**
```bash
python wifi_auto_login.py --login
```

**To view the last 3 login attempts:**
```bash
python wifi_auto_login.py --view-logs 3
```
90 changes: 86 additions & 4 deletions wifi_auto_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import requests
import datetime
import re
import argparse
import json
import os


# --- CONFIGURATION ---
CONFIG_PATH = "config.json"

Expand Down Expand Up @@ -124,8 +126,88 @@ def view_logs(limit=5):
print(f"Message: {message}")
print("-" * 80)

# --- MAIN EXECUTION ---
def clear_logs():
"""Deletes all logs from the login_attempts table."""
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
cursor.execute("DELETE FROM login_attempts")
conn.commit()
conn.close()
print("✅ All logs have been cleared.")

def test_connection():
"""Tests if the login URL is reachable."""
# This URL should eventually come from a config file
url = "POST url from the inspect element" # The same URL from wifi_login()
print(f" testing connection to {url}...")
try:
response = requests.head(url, timeout=5) # Use HEAD to be efficient
if response.status_code == 200:
print(f"✅ Connection successful! The server responded with status {response.status_code}.")
else:
print(f"⚠️ Connection successful, but the server responded with status {response.status_code}.")
except requests.exceptions.RequestException as e:
print(f"❌ Connection failed: {e}")

def run_setup_wizard():
"""Guides the user through an interactive setup process."""
print("--- WiFi-Auto-Auth Interactive Setup ---")
print("This wizard will help you configure the script.")

url = input("1. Enter the POST request URL from your network's login page: ")
username = input("2. Enter your login username: ")
password = input("3. Enter your login password: ")

print("\nSetup Complete!")

if __name__ == "__main__":
setup_database() # Ensure the database is set up
wifi_login() # Attempt login
view_logs(5) # Show last 5 login attempts
parser = argparse.ArgumentParser(
description="A script to automatically log into captive portal WiFi networks."
)

parser.add_argument(
'--login',
action='store_true',
help="Perform a login attempt."
)
parser.add_argument(
'--view-logs',
nargs='?',
const=5,
type=int,
metavar='N',
help="View the last N login attempts. Defaults to 5 if no number is provided."
)
parser.add_argument(
'--setup',
action='store_true',
help="Run the interactive setup wizard to configure credentials."
)
parser.add_argument(
'--test',
action='store_true',
help="Test the connection to the login URL without logging in."
)
parser.add_argument(
'--clear-logs',
action='store_true',
help="Clear all login logs from the database."
)

args = parser.parse_args()
setup_database() # Ensure the database is always set up

if args.login:
wifi_login()
elif args.view_logs is not None:
view_logs(args.view_logs)
elif args.setup:
run_setup_wizard()
elif args.test:
test_connection()
elif args.clear_logs:
clear_logs()
else:
print("No arguments provided. Performing default login action.")
wifi_login()
view_logs(1)