Skip to content

Latest commit

 

History

37 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Not on My Network

Student Name: Sophie Hayes
Student ID: 20114793

Project Repository Repository

Video

Overview: Smart Home Network Administration + Security

Not On My Network is an IoT-based network administration tool designed to give users control over who, and what, connects to their home WiFi.

As more and more connected technologies enter our homes, "Digital Wellbeing" is becoming a priorit and people are also seeking to disconnect. This project will allow users to disconnect devices of their choosing from their home network. It will aid with security, as ony devices on the chosen list will have access to the network.

This project allows users to enforce Allow Lists (Whitelists), block intruders, and schedule "Digital Curfews" (Night Mode) using blacklists to automatically disconnect specific devices at night to encourage better sleep hygiene and habits.

Motivation

This project was created to solve two problems:

  1. Security: Users rarely check who is on their network. This tool allows users to choose allowed and restricted devices and makes intruders visible instantly via a physical dashboard (SenseHat) and mobile alerts (Blynk and discord).

  2. Digital Wellbeing: Parents or individuals often want to disconnect devices at night without physically taking them away. This project automates network restriction based on a schedule. NOTE: As this is a student project, device blocking is simulated, but could be completed using arptables.

This project will create an allowed list of devices on the network. Any other mac addresses will be disallowed. The Raspberry Pi runs python scripts that are activated mobile Blynk app button, temporarily restricting chosen devices. Additionally, a 'night-time' schedule restricts specific devices (e.g., gaming consoles) overnight and restores them in the morning.

Features

  • Active Network Scanning: Uses SCAPY and ARP protocol to detect every device on the LAN.
  • Intruder Detection: Compares active devices against a Whitelist. If an unknown device appears, the SenseHAT flashes a "Skull" alert and a notification is sent to the Blynk app and to discord.
  • Cloud Control (Blynk): View system status and toggle "Lockdown Mode" remotely via a mobile app.
  • Night Mode Automation: Automatically restricts the network between 9 PM and 8 AM (configurable via Blynk app).
  • Live Logging: Intruder alerts and weekly and daily reports are sent to discord channel using webhooks, all events in the app are logged to MongoDB Atlas (cloud) database collection and certain events trigger Blynk events and notifications, (e.g. late night overriding restriction).
  • Web Dashboard (Streamlit): A browser-based analytics center to view historical logs and intruder stats.
  • Dockerized Deployment: Runs in a container for easy installation and stability.

Architecture & Logic

This project demonstrates a multi-service architecture separating the Edge Device (Raspberry Pi) from the Cloud Services.

1. The Scanner (Edge Logic)

This project uses ARP (Address Resolution Protocol).

  • ARP operates at Layer 2 (Data Link Layer). Every device must answer ARP requests to communicate on the LAN, making it impossible to "hide" from this scanner.

  • Implementation: The Python script broadcasts Ethernet frames to ff:ff:ff:ff:ff:ff asking "Who has IP X?".

2. The Controller (State Management)

The system operates in a state loop managed by notOnMyNetwork.py:

  • Scan Phase: Scan the network.

  • Verify Phase: Compare MAC addresses against whitelist.txt and blacklist.txt.

  • Action Phase:

    • If Intruder -> Trigger Visual Alarm (SenseHAT) -> Webhook to Discord & Log to Mongo.

    • Night Mode: -> If time is > 9 PM (user can configure in blynk app), check for blacklisted devices -> Log violations.

3. Data Flow

  • Hardware: Raspberry Pi 4 + SenseHAT.

  • Protocols:

    • ARP: Local device discovery.
    • HTTPS/REST: Discord Webhooks and MongoDB Atlas API.
    • Blynk Protocol (MQTT): Bidirectional communication for mobile control.

Tech Stack

Hardware

  • Raspberry Pi 4: The central edge gateway running the scanning logic.
  • SenseHAT: Provides immediate visual feedback (LED Matrix) and physical control (Joystick). The SenseHAT provides immediate "headless" feedback (LED Matrix) without needing a monitor.

Software & Frameworks

  • Python 3: Core logic. Extensive library support for low-level networking (Scapy) and data handling (Pandas).
  • Scapy: Chosen for network scanning because it uses ARP (Address Resolution Protocol) to identify devices by MAC address.
  • Streamlit: Used to build a data-driven web dashboard quickly without complex HTML/CSS.
  • Docker: Ensures the application runs reliably on any device without dependency conflicts. Scapy requires root privileges and specific system dependencies. Docker isolates these, preventing conflicts with the host OS.

Cloud Services

  • MongoDB Atlas: A cloud-based NoSQL database used to store event logs and historical data. It was chosen for its flexibility with JSON-style log data.
  • Blynk IoT: Provides the mobile interface, event handling and push notification infrastructure.
  • Discord: Acts as a real-time logging channel for alerts.

Screenshots

Mobile App (Blynk) Web Dashboard (Streamlit) Hardware (SenseHat) Sample Output - Intruder
Blynk App Streamlit SenseHat Intruder Detection

Installation and Configuration

Prerequisites

  • Raspberry Pi (4 used in this project) with Raspberry Pi OS.
  • Docker & Docker Compose installed.
  • A Blynk Account and MongoDB Atlas Account and Discord Account.

Step 1: Clone the Repository

git clone https://github.com/Oiche000/NotOnMyNetwork.git
cd IoT-Project

Step 2: Cloud Services Configuration

Setting up MongoDB Atlas:

  1. Create a free MongoDB Atlas account and create a cluster on MongoDB Atlas.

  2. Create a Database User and password.

  3. Network Access, whitelist the Public IP of your Raspberry Pi. You can find this by running curl ifconfig.me on the Pi.

  4. Connection: Choose connect via Driver: Python 3.6+ and copy the connnection string. MongoDB Atlas Connection

Setting up Blynk

  1. Create Blynk account and create a Template.

  2. Setup Datastreams:

    • V0: Master Switch (Integer 0/1) - Trigger Network restriction/restoration
    • V2: Start Time (Integer) - configure the time
    • V3: End Time (Integer) - configure the time
  3. Setup Events for Notifications:

    • Go to the Events tab in your Template.
    • Create intruder_alert: Type = Critical, Notifications = ON, Limit = 1 Hour.
    • Create schedule_override: Type = Warning, Notifications = ON, Limit = 5 minutes - 1 hour (depending on preference).
    • Create system_log: Type = Info, Notifications = OFF, Limit = None (Show in Timeline only). Event Setup Blynk
  4. Copy your BLYNK_AUTH_TOKEN from the Device Info tab.

Setting up Discord Webhooks

  1. Create a free discord account and create a server.

  2. In your Discord Server, go to Channel Settings -> Integrations -> Webhooks.

  3. Create New Webhook -> Copy Webhook URL.

Step 4: Set up Environment Variables

Create a file named .env in the root directory to store secrets, add this file to .gitignore file if applicable:

BLYNK_AUTH=your_blynk_auth_token_here
MONGO_URI=your_mongodb_connection_string_here
DISCORD_URL=your_discord_webhook_url

Step 5: Run with Docker (Recommended)

This project requires low-level network access for scanning -> include --privileged.

Build the image.

docker build -t not-on-my-network .
docker run --privileged --network host --env-file .env not-on-my-network
Manual Installation (Virtual Env)

If not using Docker:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
sudo .venv/bin/python notOnMyNetwork.py

Step 6. Run the Dashboard

To view streamlit dashboard run following from project folder:

pip install streamlit pandas pymongo
streamlit run dashboard.py

Visuals

Mobile and Web Dashboard

Physical Alert Toggle restrictions & get alerts Analyze 7-day trends & logs Red Skull = Intruder Detected

Configuration & Customization

To ensure the system is adaptable to different home environments, the project avoids "hard-coding".

  • Environment Secrets: API keys and Database URIs are stored in .env (not committed to version control).

  • Config File: The behaviour of the app is controlled by a JSON config file that allowd adjustment of default night start/end times, location of white- and black- lists

  • State Management: Whitelists are maintained in persistent storage, allowing the system to remember devices even after a reboot.

  • Reporting Parameters (analytics.py) The analytics module is designed to be flexible. While the default dashboard shows the "Last 7 Days," the functions in analytics.py accept dynamic arguments.

  • Night Mode start/end times are controlled dynamically via the Blynk App widgets either via the mobile or web dashboards.

How to Contribute

Fork the repo.

Create a feature branch (git checkout -b feature/NewFeature).

Commit your changes.

Push to the branch and open a Pull Request.

License

MIT © Sophie Hayes

Learning and Resources and References

The following resources were instrumental in building this project. They are highly recommended for anyone replicating this work.

Network Programming

Scapy Documentation: Usage for Scanning - Used to understand ARP packet construction. Dev Dev GeeksForGeeks

Cloud & Data

MongoDB for Python: PyMongo Tutorial - Guide on CRUD operations. Followed steps in Chapter 1 of guide GeeksForGeeks - Mongo Connection

Streamlit Docs: Connect to Data - How to bind Python scripts to web UIs. Streamlit

Streamlit Youtube - Building a dashboard app

Streamlit Youtube - Dashboards

Programming is Fun - Python and Streamlit Dashboards

Fanilo Andrianasolo - Streamlit Dashboards

Streamlit to MongoDB

References

Where applicable, all other references are included in a comment near the relevant code in the code files.

Reflection

One of the biggest challenges in this project was handling the "stateless" nature of network scanning.

The Problem: The scanner detects devices now, but doesn't know if they were there 5 minutes ago.

The Solution: I implemented a robust logging system in MongoDB. By querying the last known state from the database before performing an action, the system gained "memory," allowing it to calculate things like "Late Night Restores" and "Intruder Duration" for my Dashboard.

Future Improvements: Currently, the system detects intruders but cannot physically kick them off the network (it relies on notifications). A future iteration could use arpspoof or arptables to disconnect unwanted devices. Device lists could also be read from MongoDB Atlas in the future to prevent having to read files on the device. A configuration collection could be created to control these lists as well as device parameters such as saving state and configuration if device is offline. Once re-connected, the device can get these values and apply them.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages