Found from https://vermaden.wordpress.com/2018/03/24/freebsd-network-management-with-network-sh-script/
Add yourself to network group first
pw groupmod network -m yourself
Wifi script:
#!/bin/sh
WPA_CONFIG="/etc/wpa_supplicant.conf"
echo "Enter SSID":
read SSID
echo "Enter PSK (just Enter for none)":
read PSK
echo "Do you want to add the new AP configuration:"
echo " SSID: $SSID"
echo " PSK: $PSK"
echo "to $WPA_CONFIG ? Y/N"
read ANS
if [ "$ANS" = "y" ] || [ "$ANS" = "Y" ] ; then
echo "network={" >> $WPA_CONFIG
echo "ssid=\"$SSID\"" >> $WPA_CONFIG
if [ "x$PSK" = "x" ] ; then
echo key_mgmt=NONE >> $WPA_CONFIG
else
echo "psk=\"$PSK\"" >> $WPA_CONFIG
fi
echo "scan_ssid=1" >> $WPA_CONFIG
echo "priority=15" >> $WPA_CONFIG
echo "}" >> $WPA_CONFIG
echo "Done!"
fi
===================================================
Other useful network commands
https://srobb.net/fbsdquickwireless.html
https://docs.freebsd.org/en/books/handbook/advanced-networking/#network-wireless
Wlan(0) scan
ifconfig wlan0 up list scan
Wireless setup
bsdconfig wireless
Network re-start
#!/bin/sh
#
# RJP 25.6.2025 restart network script
# Packages sudo, networkmgr, xterm and yad must be installed
#
#
yad --text="Would like to restart network?" --title="QUESTION"
if [ $? = 0 ];
then
/bin/sh -c "xterm -e 'sudo service netif restart' && yad --center --borders=5 --width=400 --text-align=center --button=ok:1 --title='Network re-started' --buttons-layout=center"
else exit 0
fi
Network monitoring
#!/bin/sh
# RJP 27.6.2025
# simple script for monitoring network traffic
#
xterm -e watch netstat -tunlap