-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan
More file actions
executable file
·62 lines (52 loc) · 1.88 KB
/
scan
File metadata and controls
executable file
·62 lines (52 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# CyberPower PDU Bridge
# Created by Matthew Valancy, Valpatel Software LLC
# Copyright 2026 GPL-3.0 License
# https://github.com/mvalancy/CyberPower-PDU
set -euo pipefail
cd "$(dirname "$0")"
source lib/common.sh
check_help "${1:-}" "./scan" "Discover CyberPower PDUs on the network" \
"Usage: ./scan [--subnet 192.168.1.0/24] [--community public]
Scans a subnet for CyberPower PDUs via SNMP and prints a
table of discovered devices with model, serial, and outlet count.
Options:
--subnet CIDR Subnet to scan (default: auto-detect)
--community STRING SNMP community string (default: public)
--timeout SECONDS Per-host timeout (default: 1)
Examples:
./scan
./scan --subnet 192.168.20.0/24
./scan --subnet 10.0.0.0/24 --community private"
setup_log "scan"
banner
# Parse arguments
SUBNET=""
COMMUNITY="public"
TIMEOUT="1"
while [ $# -gt 0 ]; do
case "$1" in
--subnet) SUBNET="$2"; shift 2 ;;
--community) COMMUNITY="$2"; shift 2 ;;
--timeout) TIMEOUT="$2"; shift 2 ;;
*) error "Unknown argument: $1"; exit 1 ;;
esac
done
# Try running via Docker first, fall back to native Python
if docker compose ps bridge --format '{{.Name}}' 2>/dev/null | grep -q bridge; then
step "Scanning for CyberPower PDUs via Docker"
ARGS="--community $COMMUNITY --timeout $TIMEOUT"
[ -n "$SUBNET" ] && ARGS="$ARGS --subnet $SUBNET"
docker compose exec bridge python -m bridge.src.discovery $ARGS
elif python3 -c "import pysnmp" 2>/dev/null; then
step "Scanning for CyberPower PDUs (native Python)"
ARGS="--community $COMMUNITY --timeout $TIMEOUT"
[ -n "$SUBNET" ] && ARGS="$ARGS --subnet $SUBNET"
python3 -m bridge.src.discovery $ARGS
else
error "Cannot run scan — either start the stack (./start) or install pysnmp-lextudio"
info " pip install pysnmp-lextudio"
exit 1
fi
echo ""
success "Log saved to $LOG_FILE"