feat: add password overlay for network popout + redesign
C++ / fmt (pull_request) Successful in 4s
JS/TS / fmt (pull_request) Successful in 11s
JS/TS / lint (pull_request) Successful in 24s
Python / fmt (pull_request) Successful in 30s
Python / lint (pull_request) Successful in 34s
Python / test (pull_request) Successful in 53s
C++ / build (pull_request) Successful in 1m52s
Rust / fmt (pull_request) Successful in 1m14s
Rust / build (pull_request) Successful in 1m57s
Rust / clippy (pull_request) Successful in 2m0s
Python / buildcheck (pull_request) Successful in 2m37s
C++ / clang-tidy (pull_request) Successful in 3m43s
C++ / fmt (pull_request) Successful in 4s
JS/TS / fmt (pull_request) Successful in 11s
JS/TS / lint (pull_request) Successful in 24s
Python / fmt (pull_request) Successful in 30s
Python / lint (pull_request) Successful in 34s
Python / test (pull_request) Successful in 53s
C++ / build (pull_request) Successful in 1m52s
Rust / fmt (pull_request) Successful in 1m14s
Rust / build (pull_request) Successful in 1m57s
Rust / clippy (pull_request) Successful in 2m0s
Python / buildcheck (pull_request) Successful in 2m37s
C++ / clang-tidy (pull_request) Successful in 3m43s
This commit is contained in:
+159
-24
@@ -1,16 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =============================================================================
|
||||
|
||||
# wifi-sim.sh — Virtual WiFi environment for development & testing
|
||||
|
||||
#
|
||||
# Creates 3 dummy networks using mac80211_hwsim + hostapd:
|
||||
# - FreeWifi (open, strong signal, ch 1)
|
||||
# - OfficeNetwork (open, medium signal, ch 6)
|
||||
# - HomeNetwork (WPA2, weak signal, ch 11)
|
||||
|
||||
# Creates 3 dummy networks using mac80211_hwsim + hostapd + dnsmasq:
|
||||
|
||||
# - FreeWifi (open, strong signal, ch 1)
|
||||
|
||||
# - OfficeNetwork (open, medium signal, ch 6)
|
||||
|
||||
# - HomeNetwork (WPA2, weak signal, ch 11)
|
||||
|
||||
#
|
||||
|
||||
# Usage:
|
||||
# sudo ./wifi-sim.sh start
|
||||
# sudo ./wifi-sim.sh stop
|
||||
# sudo ./wifi-sim.sh status
|
||||
|
||||
# sudo ./wifi-sim.sh start
|
||||
|
||||
# sudo ./wifi-sim.sh stop
|
||||
|
||||
# sudo ./wifi-sim.sh status
|
||||
|
||||
# =============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
@@ -23,11 +36,27 @@ SSID_SECURE="HomeNetwork" # WPA2 network, weak signal
|
||||
WIFI_PASSWORD="testpassword123"
|
||||
|
||||
# TX power levels in mBm (millibel-milliwatts). Higher = stronger signal.
|
||||
|
||||
# These affect the RSSI reported to scanning clients.
|
||||
|
||||
TXPOWER_STRONG=3000 # 30 dBm
|
||||
TXPOWER_MEDIUM=1500 # 15 dBm
|
||||
TXPOWER_WEAK=100 # 1 dBm
|
||||
|
||||
# Per-network IP plan for DHCP.
|
||||
|
||||
AP1_IP="10.10.1.1"
|
||||
AP1_RANGE_START="10.10.1.50"
|
||||
AP1_RANGE_END="10.10.1.150"
|
||||
|
||||
AP2_IP="10.10.2.1"
|
||||
AP2_RANGE_START="10.10.2.50"
|
||||
AP2_RANGE_END="10.10.2.150"
|
||||
|
||||
AP3_IP="10.10.3.1"
|
||||
AP3_RANGE_START="10.10.3.50"
|
||||
AP3_RANGE_END="10.10.3.150"
|
||||
|
||||
RUN_DIR="/tmp/wifi-sim"
|
||||
|
||||
# --- Helpers -----------------------------------------------------------------
|
||||
@@ -36,8 +65,14 @@ die() {
|
||||
echo "ERROR: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
info() { echo "[*] $*"; }
|
||||
ok() { echo "[+] $*"; }
|
||||
|
||||
info() {
|
||||
echo "[*] $*"
|
||||
}
|
||||
|
||||
ok() {
|
||||
echo "[+] $*"
|
||||
}
|
||||
|
||||
require_cmds() {
|
||||
local missing=()
|
||||
@@ -46,7 +81,7 @@ require_cmds() {
|
||||
done
|
||||
if [[ ${#missing[@]} -gt 0 ]]; then
|
||||
die "Missing required tools: ${missing[*]}
|
||||
Install with: sudo apt install hostapd wpasupplicant iw"
|
||||
Install with: sudo apt install hostapd dnsmasq wpasupplicant iw"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -54,11 +89,60 @@ get_phy_for_iface() {
|
||||
iw dev "$1" info | awk '/wiphy/{print "phy"$2}'
|
||||
}
|
||||
|
||||
start_dnsmasq() {
|
||||
local name="$1"
|
||||
local iface="$2"
|
||||
local gw_ip="$3"
|
||||
local dhcp_start="$4"
|
||||
local dhcp_end="$5"
|
||||
|
||||
dnsmasq \
|
||||
--interface="$iface" \
|
||||
--bind-interfaces \
|
||||
--except-interface=lo \
|
||||
--port=0 \
|
||||
--no-resolv \
|
||||
--no-hosts \
|
||||
--dhcp-authoritative \
|
||||
--dhcp-range="${dhcp_start},${dhcp_end},255.255.255.0,12h" \
|
||||
--dhcp-option=3,"$gw_ip" \
|
||||
--dhcp-option=6,"$gw_ip" \
|
||||
--pid-file="$RUN_DIR/${name}.dnsmasq.pid" \
|
||||
--dhcp-leasefile="$RUN_DIR/${name}.leases" \
|
||||
>"$RUN_DIR/${name}.dnsmasq.log" 2>&1 ||
|
||||
{
|
||||
cat "$RUN_DIR/${name}.dnsmasq.log"
|
||||
die "dnsmasq failed for $name. See log above."
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
stop_pidfile() {
|
||||
local pidfile="$1"
|
||||
local label="$2"
|
||||
|
||||
if [[ -f "$pidfile" ]]; then
|
||||
local pid
|
||||
pid="$(cat "$pidfile")"
|
||||
if kill "$pid" 2>/dev/null; then
|
||||
info "Stopped $label (PID $pid)"
|
||||
fi
|
||||
rm -f "$pidfile"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
remove_iface_addr() {
|
||||
local iface="$1"
|
||||
local cidr="$2"
|
||||
ip addr del "$cidr" dev "$iface" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# --- Start -------------------------------------------------------------------
|
||||
|
||||
cmd_start() {
|
||||
[[ $EUID -ne 0 ]] && die "Please run as root: sudo $0 start"
|
||||
require_cmds hostapd iw ip
|
||||
require_cmds hostapd dnsmasq iw ip
|
||||
|
||||
if [[ -d "$RUN_DIR" && -f "$RUN_DIR/interfaces" ]]; then
|
||||
die "wifi-sim appears to already be running. Run 'sudo $0 stop' first."
|
||||
@@ -75,7 +159,7 @@ cmd_start() {
|
||||
die "mac80211_hwsim is already loaded. Run 'sudo $0 stop' or 'sudo rmmod mac80211_hwsim' first."
|
||||
fi
|
||||
modprobe mac80211_hwsim radios=4
|
||||
sleep 1 # Give the kernel a moment to register all interfaces
|
||||
sleep 1
|
||||
|
||||
# Find the interfaces created by our modprobe
|
||||
AFTER=($(iw dev 2>/dev/null | awk '/Interface/{print $2}' | grep -v '^hwsim'))
|
||||
@@ -97,30 +181,31 @@ cmd_start() {
|
||||
info "Interfaces assigned: AP1=$AP1 AP2=$AP2 AP3=$AP3 Client=$CLIENT"
|
||||
echo "$AP1 $AP2 $AP3 $CLIENT" >"$RUN_DIR/interfaces"
|
||||
|
||||
# Prevent NetworkManager from fighting us over these interfaces
|
||||
# Prevent NetworkManager from fighting us over the AP interfaces.
|
||||
# Leave the client managed so your app can use NetworkManager normally.
|
||||
if command -v nmcli &>/dev/null && nmcli general status &>/dev/null 2>&1; then
|
||||
info "Marking interfaces as unmanaged in NetworkManager..."
|
||||
info "Marking AP interfaces as unmanaged in NetworkManager..."
|
||||
for iface in "$AP1" "$AP2" "$AP3"; do
|
||||
nmcli device set "$iface" managed no 2>/dev/null || true
|
||||
done
|
||||
|
||||
nmcli device set "$CLIENT" managed yes
|
||||
nmcli device set "$CLIENT" managed yes 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Set TX power on each physical radio to simulate signal strength differences.
|
||||
# mac80211_hwsim factors TX power into the RSSI reported to scanning clients.
|
||||
# Note: for precise RSSI control, consider 'wmediumd' (a wireless medium daemon).
|
||||
info "Setting TX power levels for signal strength simulation..."
|
||||
PHY1=$(get_phy_for_iface "$AP1")
|
||||
PHY2=$(get_phy_for_iface "$AP2")
|
||||
PHY3=$(get_phy_for_iface "$AP3")
|
||||
|
||||
iw phy "$PHY1" set txpower fixed $TXPOWER_STRONG
|
||||
iw phy "$PHY2" set txpower fixed $TXPOWER_MEDIUM
|
||||
iw phy "$PHY3" set txpower fixed $TXPOWER_WEAK
|
||||
iw phy "$PHY1" set txpower fixed "$TXPOWER_STRONG"
|
||||
iw phy "$PHY2" set txpower fixed "$TXPOWER_MEDIUM"
|
||||
iw phy "$PHY3" set txpower fixed "$TXPOWER_WEAK"
|
||||
|
||||
# --- hostapd config: AP1 (open, strong, channel 1) -----------------------
|
||||
cat >"$RUN_DIR/ap1.conf" <<EOF
|
||||
|
||||
interface=$AP1
|
||||
driver=nl80211
|
||||
ssid=$SSID_STRONG
|
||||
@@ -133,6 +218,7 @@ EOF
|
||||
|
||||
# --- hostapd config: AP2 (open, medium, channel 6) -----------------------
|
||||
cat >"$RUN_DIR/ap2.conf" <<EOF
|
||||
|
||||
interface=$AP2
|
||||
driver=nl80211
|
||||
ssid=$SSID_MEDIUM
|
||||
@@ -145,6 +231,7 @@ EOF
|
||||
|
||||
# --- hostapd config: AP3 (WPA2, weak, channel 11) ------------------------
|
||||
cat >"$RUN_DIR/ap3.conf" <<EOF
|
||||
|
||||
interface=$AP3
|
||||
driver=nl80211
|
||||
ssid=$SSID_SECURE
|
||||
@@ -182,6 +269,20 @@ EOF
|
||||
die "hostapd failed for AP3. See log above."
|
||||
}
|
||||
|
||||
# Give each AP a gateway IP and start DHCP on each one.
|
||||
info "Configuring AP addresses and DHCP servers..."
|
||||
ip link set "$AP1" up
|
||||
ip link set "$AP2" up
|
||||
ip link set "$AP3" up
|
||||
|
||||
ip addr add "$AP1_IP/24" dev "$AP1"
|
||||
ip addr add "$AP2_IP/24" dev "$AP2"
|
||||
ip addr add "$AP3_IP/24" dev "$AP3"
|
||||
|
||||
start_dnsmasq "ap1" "$AP1" "$AP1_IP" "$AP1_RANGE_START" "$AP1_RANGE_END"
|
||||
start_dnsmasq "ap2" "$AP2" "$AP2_IP" "$AP2_RANGE_START" "$AP2_RANGE_END"
|
||||
start_dnsmasq "ap3" "$AP3" "$AP3_IP" "$AP3_RANGE_START" "$AP3_RANGE_END"
|
||||
|
||||
# Bring up the client interface so it's ready to scan/connect
|
||||
ip link set "$CLIENT" up
|
||||
|
||||
@@ -200,14 +301,19 @@ EOF
|
||||
echo " WPA2 password : $WIFI_PASSWORD"
|
||||
echo " Client iface : $CLIENT (use this in your code)"
|
||||
echo ""
|
||||
echo " Gateway IPs / DHCP:"
|
||||
echo " $SSID_STRONG -> $AP1_IP/24"
|
||||
echo " $SSID_MEDIUM -> $AP2_IP/24"
|
||||
echo " $SSID_SECURE -> $AP3_IP/24"
|
||||
echo ""
|
||||
echo " Useful commands:"
|
||||
echo " Scan for networks : sudo iw dev $CLIENT scan | grep -E 'SSID|signal'"
|
||||
echo " Connect (open) : sudo iw dev $CLIENT connect \"$SSID_STRONG\""
|
||||
echo " Connect (WPA2) : sudo wpa_supplicant -Dnl80211 -i$CLIENT \\"
|
||||
echo " -c <(wpa_passphrase \"$SSID_SECURE\" \"$WIFI_PASSWORD\")"
|
||||
echo " Connect (WPA2) : sudo nmcli device wifi connect \"$SSID_SECURE\" password \"$WIFI_PASSWORD\" ifname \"$CLIENT\""
|
||||
echo " Stop simulation : sudo $0 stop"
|
||||
echo ""
|
||||
echo " Logs: $RUN_DIR/ap{1,2,3}.log"
|
||||
echo " Logs: $RUN_DIR/ap{1,2,3}.log and $RUN_DIR/ap{1,2,3}.dnsmasq.log"
|
||||
|
||||
}
|
||||
|
||||
# --- Stop --------------------------------------------------------------------
|
||||
@@ -218,6 +324,19 @@ cmd_stop() {
|
||||
info "Stopping virtual WiFi environment..."
|
||||
local had_something=false
|
||||
|
||||
# Stop dnsmasq instances first.
|
||||
for ap in ap1 ap2 ap3; do
|
||||
PID_FILE="$RUN_DIR/$ap.dnsmasq.pid"
|
||||
if [[ -f "$PID_FILE" ]]; then
|
||||
PID=$(cat "$PID_FILE")
|
||||
if kill "$PID" 2>/dev/null; then
|
||||
info "Stopped dnsmasq for $ap (PID $PID)"
|
||||
fi
|
||||
rm -f "$PID_FILE"
|
||||
had_something=true
|
||||
fi
|
||||
done
|
||||
|
||||
# Kill hostapd processes via PID files
|
||||
for ap in ap1 ap2 ap3; do
|
||||
PID_FILE="$RUN_DIR/$ap.pid"
|
||||
@@ -231,9 +350,14 @@ cmd_stop() {
|
||||
fi
|
||||
done
|
||||
|
||||
# Re-enable NetworkManager management for these interfaces
|
||||
# Restore addresses if we still know the interface names.
|
||||
if [[ -f "$RUN_DIR/interfaces" ]]; then
|
||||
read -r AP1 AP2 AP3 CLIENT <"$RUN_DIR/interfaces"
|
||||
|
||||
remove_iface_addr "$AP1" "$AP1_IP/24"
|
||||
remove_iface_addr "$AP2" "$AP2_IP/24"
|
||||
remove_iface_addr "$AP3" "$AP3_IP/24"
|
||||
|
||||
if command -v nmcli &>/dev/null; then
|
||||
for iface in "$AP1" "$AP2" "$AP3" "$CLIENT"; do
|
||||
nmcli device set "$iface" managed yes 2>/dev/null || true
|
||||
@@ -255,6 +379,7 @@ cmd_stop() {
|
||||
else
|
||||
echo "Nothing was running."
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# --- Status ------------------------------------------------------------------
|
||||
@@ -286,6 +411,16 @@ cmd_status() {
|
||||
echo " hostapd ($ap) PID=$PID DEAD (check $RUN_DIR/$ap.log)"
|
||||
fi
|
||||
fi
|
||||
|
||||
DNSMASQ_PID_FILE="$RUN_DIR/$ap.dnsmasq.pid"
|
||||
if [[ -f "$DNSMASQ_PID_FILE" ]]; then
|
||||
PID=$(cat "$DNSMASQ_PID_FILE")
|
||||
if kill -0 "$PID" 2>/dev/null; then
|
||||
echo " dnsmasq ($ap) PID=$PID running"
|
||||
else
|
||||
echo " dnsmasq ($ap) PID=$PID DEAD (check $RUN_DIR/$ap.dnsmasq.log)"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@@ -298,7 +433,7 @@ status) cmd_status ;;
|
||||
*)
|
||||
echo "Usage: sudo $0 {start|stop|status}"
|
||||
echo ""
|
||||
echo " start Load mac80211_hwsim and bring up 3 virtual APs"
|
||||
echo " start Load mac80211_hwsim and bring up 3 virtual APs with DHCP"
|
||||
echo " stop Tear down all virtual interfaces and unload module"
|
||||
echo " status Show current state of interfaces and processes"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user