A lightweight, cross platform network device monitor that detects when devices join or rejoin your local network and sends Telegram notifications.
- Periodic Network Scanning - Scans your network every minute (configurable) for connected devices
- New Device Detection - Alerts when a device never seen before joins the network
- Rejoin Detection - Alerts when a known device returns after being offline
- Telegram Notifications - Real time notifications to your Telegram
- SQLite Persistence - Stores device history and configuration
- Manufacturer Detection - Identifies device manufacturers via MAC OUI lookup
- Flexible Configuration - CLI flags with database backed defaults
- Cross Platform - Works on Linux and macOS
- Service Installation - Auto starts on boot (user level, no root required)
# Clone the repository
git clone https://github.com/pyprism/LANSentry.git
cd lansentry
# Build
go build -o lansentry ./cmd/netwatcher
# Optional: Install to PATH
sudo mv lansentry /usr/local/bin/For best results, install arp-scan:
macOS:
brew install arp-scanLinux (Debian/Ubuntu):
sudo apt install arp-scanLinux (Fedora/RHEL):
sudo dnf install arp-scanNote: LANSentry works without
arp-scanusing a fallback ping sweep + ARP table method, butarp-scanprovides faster and more reliable results.
# Run a single scan
./lansentry --one-shot
# Run as daemon (foreground)
./lansentry
# Run with verbose output
./lansentry --verbose# Set scan interval (in minutes)
./lansentry --scan-interval 5
# Set rejoin threshold (in days)
./lansentry --rejoin-days 2
# Specify network interface
./lansentry --interface en0
# Configure Telegram notifications
./lansentry --telegram-token "BOT_TOKEN" --telegram-chat "CHAT_ID"
# Disable new device notifications
./lansentry --notify-new=false
# Disable rejoin notifications
./lansentry --notify-rejoin=falseInstall as a user level service (auto-starts on login/boot):
# Install the service
./lansentry --install
# Uninstall the service
./lansentry --uninstallmacOS: Creates a launchd agent in ~/Library/LaunchAgents/
Linux: Creates a systemd user service in ~/.config/systemd/user/
| Flag | Description | Default |
|---|---|---|
--scan-interval |
Scan interval in minutes | 1 |
--rejoin-days |
Days before device is considered rejoining | 1 |
--notify-new |
Enable new device notifications | true |
--notify-rejoin |
Enable rejoin notifications | true |
--telegram-token |
Telegram bot token | (none) |
--telegram-chat |
Telegram chat ID (private: 123..., group/supergroup: -100...) |
(none) |
--interface |
Network interface to scan | (auto) |
--db-path |
Path to SQLite database | ~/.config/lansentry/lansentry.db |
--install |
Install as system service | - |
--uninstall |
Uninstall system service | - |
--one-shot |
Run single scan and exit | false |
--verbose |
Enable verbose logging | false |
--version |
Show version info | - |
- Create a bot with @BotFather and copy the bot token.
- Open your bot chat in Telegram and send a message (for groups, add the bot to the group and send a message there).
- Query updates and inspect
message.chat.id:
curl "https://api.telegram.org/bot<TOKEN>/getUpdates"-
Use the returned
chat.idas--telegram-chat:- Private chat IDs are usually positive (example:
123456789) - Group/supergroup IDs are usually negative (example:
-1001234567890)
- Private chat IDs are usually positive (example:
-
Configure LANSentry:
./lansentry --telegram-token "123456:ABC..." --telegram-chat "123456789"If getUpdates returns an empty result:
- Send a fresh message to the bot or group and run the command again.
- For groups, confirm the bot is added and allowed to read messages.
- If you already consumed updates in another script, clear offsets there or retry after a new message.
LANSentry stores all data in SQLite:
- Default location:
~/.config/lansentry/lansentry.db - Device records: MAC, IP, hostname, manufacturer, timestamps
- Configuration: Persisted settings
- Scan history: Historical scan results
-
Startup:
- Load configuration from database
- Apply CLI flag overrides
- Initialize network scanner
-
Each Scan Interval:
- Send ARP requests to all IPs in local subnet
- Collect responses to build device list
- Compare with stored device database
- Detect new devices and rejoins
- Send notifications (if configured)
- Update database
-
Device States:
- New: MAC address never seen before
- Rejoined: Known device offline longer than threshold
LANSentry uses system ARP commands that may require elevated privileges for raw socket access:
Option 1: Run with sudo (not recommended for daemon)
sudo ./lansentryOption 2: Set capabilities (Linux only)
sudo setcap cap_net_raw+ep ./lansentryOption 3: Use arp-scan (recommended)
Install arp-scan and run it with appropriate permissions.
macOS: ~/Library/Logs/LANSentry/
Linux: ~/.local/share/lansentry/logs/
View systemd logs (Linux):
journalctl --user -u lansentry -fMIT