is_wifi_interface() { which iw > /dev/null 2>&1 && iw dev $1 info > /dev/null 2>&1 && return 0 if which iwconfig > /dev/null 2>&1 && iwconfig $1 > /dev/null 2>&1; then USE_IWCONFIG=1 return 0 fi return 1 }
check_supported() { # Check if the wireless card supports Access Point mode. This script won't work if it doesn't support it if [[ ! $(iw list 2>&1 | grep -A6 "Supported interface modes" | grep AP$) ]]; then show_err "Your wireless card or driver does not support Access Point mode" exit 1 fi }
check_network() { # Check if Wireless is disabled if [[ $(iwconfig "$INTERFACE_WLAN" 2>&1 | grep "Tx-Power=off") ]]; then show_err "WiFi is disabled, please enable WiFi before running this script" exit 1 # Check if Wireless is enabled, but connected to a network elif [[ ! $(iwconfig "$INTERFACE_WLAN" 2>&1 | grep "ESSID:off/any") \ && $(iwconfig "$INTERFACE_WLAN" 2>&1 | grep "ESSID:") ]]; then show_err "Please disconnect WiFi before proceeding" exit 1 fi }
cat <<EOF | tee $CONFDIR/dnsmasq.conf > /dev/null 2>&1 # Bind to only one interface bind-interfaces # Choose interface for binding interface=$INTERFACE_WLAN # Specify range of IP addresses for DHCP leases dhcp-range=$DHCP_RANGE,12h #INTERFACE_NET=$INTERFACE_NET EOF
实际生成的dnsmasq.conf文件示例如下:
1 2 3 4 5 6
# Bind to only one interface bind-interfaces # Choose interface for binding interface=wlan0 # Specify range of IP addresses for DHCP leases dhcp-range=192.168.250.1,192.168.250.200,255.255.255.0,12h