-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathstart_linux.sh
More file actions
executable file
·71 lines (59 loc) · 2.47 KB
/
Copy pathstart_linux.sh
File metadata and controls
executable file
·71 lines (59 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
67
68
69
70
71
#!/bin/bash
# ═══════════════════════════════════════════════════════
# NetControl - Linux Launcher
# Enables IP forwarding and runs with sudo
# ═══════════════════════════════════════════════════════
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$SCRIPT_DIR/NetControl"
BINARY="$PROJECT_DIR/bin/Release/net8.0/NetControl"
echo -e "${CYAN}"
echo "╔══════════════════════════════════════╗"
echo "║ NetControl - Linux Launcher ║"
echo "╚══════════════════════════════════════╝"
echo -e "${NC}"
# ── Check if built ──
if [ ! -f "$BINARY" ] && [ ! -f "$BINARY.dll" ]; then
echo -e "${RED}[ERROR] NetControl not built. Run ./install_linux.sh first.${NC}"
exit 1
fi
# ── Check for root ──
if [ "$EUID" -ne 0 ]; then
echo -e "${YELLOW}[!] NetControl requires root privileges for network access.${NC}"
echo -e "${YELLOW} Relaunching with sudo...${NC}"
echo ""
exec sudo bash "$0" "$@"
fi
# ── Cleanup Handler ──
cleanup() {
echo ""
echo -e "${YELLOW}[Cleanup] Restoring network state...${NC}"
if [ -n "$CURRENT_FWD" ]; then
sysctl -w net.ipv4.ip_forward=$CURRENT_FWD > /dev/null 2>&1
echo -e "${GREEN}[OK] IP forwarding restored to previous state ($CURRENT_FWD).${NC}"
fi
# Flush residual tc qdiscs if tc is present
if command -v tc >/dev/null 2>&1; then
for iface in $(ip -o link show 2>/dev/null | awk -F': ' '{print $2}' | cut -d'@' -f1 | grep -v "lo"); do
tc qdisc del dev "$iface" root >/dev/null 2>&1 || true
done
fi
}
trap cleanup EXIT
# ── Enable IP forwarding (required for MITM) ──
echo -e "${YELLOW}[1/2] Enabling IP forwarding...${NC}"
CURRENT_FWD=$(cat /proc/sys/net/ipv4/ip_forward)
sysctl -w net.ipv4.ip_forward=1 > /dev/null 2>&1
echo -e "${GREEN}[OK] IP forwarding enabled.${NC}"
# ── Launch ──
echo -e "${YELLOW}[2/2] Launching NetControl...${NC}"
echo ""
cd "$PROJECT_DIR"
dotnet run --configuration Release --no-build
EXIT_CODE=$?
exit $EXIT_CODE