Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·66 lines (58 loc) · 2.47 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·66 lines (58 loc) · 2.47 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
63
64
65
66
#!/usr/bin/env bash
#
# Set up netmapper's ISOLATED environment.
#
# All Python packages are installed into ./.venv next to this script.
# Nothing is installed system-wide and no `sudo`/apt is used here.
#
# ./setup.sh # core deps only (networkx, pyvis) — runs out of the box
# ./setup.sh --full # also install optional collector deps (nmap/scapy/snmp)
#
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV="$HERE/.venv"
PY="$VENV/bin/python"
echo "[netmapper] isolated environment -> $VENV"
if ! command -v python3 >/dev/null 2>&1; then
echo "ERROR: python3 not found. Install it first (e.g. 'apt install python3')." >&2
exit 1
fi
# 1) Create the venv.
# On minimal Debian, ensurepip can be missing (python3-venv not installed),
# which makes the normal `python3 -m venv` fail. Fall back to creating the
# venv without pip and bootstrapping pip via get-pip.py — so the user still
# doesn't have to install any system package.
if [ ! -x "$PY" ]; then
if python3 -m venv "$VENV" 2>/dev/null && [ -x "$VENV/bin/pip" ]; then
echo "[netmapper] created venv"
else
echo "[netmapper] standard venv unavailable; bootstrapping pip manually"
rm -rf "$VENV"
python3 -m venv --without-pip "$VENV"
"$PY" -c "import urllib.request; urllib.request.urlretrieve(
'https://bootstrap.pypa.io/get-pip.py', '$HERE/get-pip.py')"
"$PY" "$HERE/get-pip.py"
rm -f "$HERE/get-pip.py"
fi
fi
# 2) Install dependencies into the venv ONLY.
"$PY" -m pip install --quiet --upgrade pip
if [ "${1:-}" = "--full" ]; then
echo "[netmapper] installing core + optional collector deps..."
"$PY" -m pip install --quiet networkx pyvis python-nmap scapy \
mac-vendor-lookup pysnmp
cat <<'EOF'
NOTE: a few collectors also need system pieces this script does NOT install
(by design — they affect the whole OS or need privileges):
* nmap collector -> the `nmap` binary (sudo apt install nmap)
* arp / traceroute -> root / sudo (scapy uses raw sockets)
* snmp / lldp collector -> SNMP read access on your switches/routers
The pure-Python `pingsweep` collector needs none of these and is the default
fallback, so netmapper works even without them.
EOF
else
echo "[netmapper] installing core deps (networkx, pyvis)..."
"$PY" -m pip install --quiet networkx pyvis
echo "[netmapper] tip: run './setup.sh --full' to add nmap/scapy/snmp collectors"
fi
echo "[netmapper] done. Try: ./netmapper scan --subnet 192.168.1.0/24"