Skip to content

Latest commit

ย 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ NetGuard โ€” Professional Website Blocker

A stunning, glassmorphism-themed Windows desktop application that blocks websites by safely modifying the C:\Windows\System32\drivers\etc\hosts file. Built with Flask, modern HTML/CSS/JS, and a premium security dashboard aesthetic.

Python Flask Platform License


โœจ Features

  • ๐ŸŽจ Glassmorphism UI โ€” Premium dark-themed dashboard with animated gradient orbs, frosted-glass cards, and the Outfit font
  • ๐Ÿ”’ Safe Hosts File Editing โ€” Uses unique # NETGUARD-START / # NETGUARD-END tags so it never touches your manual entries
  • ๐Ÿง  Smart Domain Cleaner โ€” Paste any URL (even with paths, query params, or subdomains) and NetGuard extracts the clean hostname
  • ๐ŸŒ Subdomain Auto-Expansion โ€” Blocking youtube.com automatically blocks www., m., music., studio., and youtu.be
  • โšก Quick Presets โ€” Block entire categories (Social Media, Gaming, Entertainment) with one click
  • ๐Ÿ”„ DNS Cache Invalidation โ€” Automatically runs ipconfig /flushdns after every change
  • ๐Ÿ“‹ Automatic Backups โ€” Creates timestamped backups before every modification
  • โš ๏ธ Admin Detection โ€” Prominent red warning banner if not running as Administrator

๐Ÿ“‹ Prerequisites

  • Windows 10/11
  • Python 3.10 or higher
  • Administrator privileges (required to modify the hosts file)

๐Ÿš€ Quick Start

1. Install Dependencies

pip install flask

2. Run as Administrator

โš ๏ธ CRITICAL: You must run this application from an Administrator Command Prompt:

  1. Press Win + S, type cmd
  2. Right-click Command Prompt โ†’ Run as administrator
  3. Navigate to the NetGuard folder:
    cd "D:\Cyber Project\NEW\NetGuard"
  4. Launch the app:
    python app.py
  5. Open your browser to http://127.0.0.1:5000

If you forget to run as Administrator, the UI will show a prominent red warning banner.


โš ๏ธ IMPORTANT: Disable Secure DNS (DNS-over-HTTPS / DoH)

Why This Matters

Modern browsers can bypass the hosts file entirely by using DNS-over-HTTPS (DoH) or DNS-over-TLS (DoT). When Secure DNS is enabled, your browser sends DNS queries directly to external resolvers (like Google 8.8.8.8 or Cloudflare 1.1.1.1), completely skipping the local hosts file.

This means NetGuard will not work unless you disable Secure DNS in your browser.

What is DNS-over-HTTPS (DoH)?

DNS-over-HTTPS is a protocol that encrypts DNS queries by sending them over HTTPS instead of the traditional unencrypted UDP port 53. While this improves privacy by preventing ISP snooping, it also means:

  1. Your browser ignores the local hosts file
  2. All DNS resolution happens through external servers
  3. Hosts-based blockers like NetGuard become completely ineffective

How to Disable Secure DNS

Google Chrome

  1. Click the โ‹ฎ menu โ†’ Settings
  2. Navigate to Privacy and security โ†’ Security
  3. Scroll down to Advanced
  4. Toggle "Use Secure DNS" to OFF
  5. Restart Chrome

Alternatively, go to: chrome://settings/security and disable Secure DNS.

Microsoft Edge

  1. Click the โ‹ฏ menu โ†’ Settings
  2. Navigate to Privacy, search, and services
  3. Scroll down to Security
  4. Toggle "Use secure DNS to specify how names are resolved" to OFF
  5. Restart Edge

Alternatively, go to: edge://settings/privacy and disable Secure DNS.

Mozilla Firefox

  1. Click the โ˜ฐ menu โ†’ Settings
  2. Navigate to Privacy & Security
  3. Scroll to the very bottom โ†’ DNS over HTTPS
  4. Set it to "Off" or "Default Protection" (not "Max Protection")
  5. Restart Firefox

Alternatively, go to: about:preferences#privacy and find the DNS over HTTPS section.

System-Wide (Windows 11)

If you want to disable DoH at the OS level:

  1. Open Settings โ†’ Network & Internet โ†’ Wi-Fi (or Ethernet)
  2. Click on your active connection โ†’ DNS server assignment โ†’ Edit
  3. Turn off "DNS over HTTPS"
  4. Click Save

Verify DoH is Disabled

After disabling, visit these URLs to confirm:

  • Chrome: chrome://net-internals/#dns โ€” Check "Secure DNS" status
  • Firefox: about:networking#dns โ€” Verify DoH is not active
  • Online test: Visit https://1.1.1.1/help โ€” "Using DNS over HTTPS (DoH)" should show No

๐Ÿ“ Project Structure

NetGuard/
โ”œโ”€โ”€ app.py                  # Flask application & API routes
โ”œโ”€โ”€ hosts_manager.py        # Hosts file read/write logic
โ”œโ”€โ”€ domain_cleaner.py       # URL parsing & subdomain expansion
โ”œโ”€โ”€ presets.py              # Preset category definitions
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ index.html          # Main dashboard HTML
โ”œโ”€โ”€ static/
โ”‚   โ”œโ”€โ”€ css/
โ”‚   โ”‚   โ””โ”€โ”€ style.css       # Glassmorphism stylesheet
โ”‚   โ””โ”€โ”€ js/
โ”‚       โ””โ”€โ”€ app.js          # Frontend application logic
โ”œโ”€โ”€ run.bat                 # One-click launcher (run as admin!)
โ””โ”€โ”€ README.md               # This file

๐Ÿ”ง API Reference

Method Endpoint Description
GET / Serve the dashboard
GET /api/status Get current blocking status & admin state
GET /api/presets Get all available presets
POST /api/block Block domain(s) โ€” body: { "domains": ["example.com"] }
POST /api/unblock Unblock domain(s) โ€” body: { "domains": ["example.com"] }
POST /api/unblock-all Remove all NetGuard blocks
POST /api/preset/<key>/apply Apply a preset by key (social_media, gaming, entertainment)

๐ŸŽฏ How It Works

Domain Cleaning

Input:  https://www.facebook.com/user/profile?q=test
Output: facebook.com

Input:  www.youtube.com/watch?v=abc123
Output: youtube.com + www.youtube.com + m.youtube.com + music.youtube.com + ...

Hosts File Tags

NetGuard only modifies lines between these markers:

# NETGUARD-START
127.0.0.1 facebook.com
::1 facebook.com
127.0.0.1 www.facebook.com
::1 www.facebook.com
# NETGUARD-END

Anything outside these tags is never touched. Your manual entries are safe.

Automatic Backups

Every modification creates a backup:

C:\Windows\System32\drivers\etc\hosts.netguard_backup_20260404_143022

๐Ÿ” Security Notes

  • Admin Check: Uses ctypes.windll.shell32.IsUserAnAdmin() to verify privileges
  • Binary Writing: Opens hosts file in wb mode with explicit \r\n line endings to prevent Windows file corruption
  • Atomic-ish Writes: Backs up before modifying; restores on failure

๐Ÿ› Troubleshooting

"Permission denied" error

  • Solution: Run your terminal as Administrator (see Quick Start)

Sites aren't being blocked

  • Solution: Disable Secure DNS / DoH in your browser (see section above)

Hosts file looks corrupted

  • Solution: Restore from the latest .netguard_backup_* file in the same directory

"Connection error" in the UI

  • Solution: Ensure the Flask server is running (check terminal for Running on http://127.0.0.1:5000)

DNS cache not flushing

  • Solution: Manually run ipconfig /flushdns in an admin terminal

๐Ÿ“ Presets

Social Media

Blocks: Facebook, Instagram, Twitter/X, TikTok, Snapchat, Pinterest, LinkedIn, Reddit, Tumblr, Threads, Mastodon, Bluesky

Gaming

Blocks: Steam, Steam Community, Epic Games, EA, Ubisoft, Battle.net, GOG, Origin, Riot Games, Roblox, Minecraft, Twitch, Discord

Entertainment

Blocks: YouTube, Netflix, Spotify, Hulu, Disney+, Prime Video, HBO Max, Crunchyroll, SoundCloud, Vimeo, Twitch, TikTok


๐Ÿ“„ License

MIT License. See LICENSE for details.


๐Ÿ™ Credits


Note: This tool is designed for personal productivity and parental control. Always respect others' privacy and terms of service.

About

Modern Windows website blocker desktop application featuring glassmorphism UI, hosts file safety management, and domain cleaning.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages