Skip to content

Instantly share code, notes, and snippets.

@HorlogeSkynet
Last active April 14, 2020 15:49
Show Gist options
  • Save HorlogeSkynet/67d83268cb3195d10b7b7200816bb773 to your computer and use it in GitHub Desktop.
Save HorlogeSkynet/67d83268cb3195d10b7b7200816bb773 to your computer and use it in GitHub Desktop.
Script for automatic creation and shutdown of a Wifi Access Point with 'create_ap'
#!/usr/bin/env bash
# @Author: Horloge-Skynet
# @Created: 2016-11-21
# @Created: 2020-04-14
# @Brief: Script for automatic creation and shutdown of a Wifi Access Point with 'create_ap'
## Some Wifi parameters ##
SSID='SkyWifi'
PASSPHRASE='SkyPass'
INTERFACE='wlan0'
CHANNEL='1'
FREQUENCY='5'
COUNTRY_FLAG='FR'
## What time slot do you want ? (Here: from 6:30 AM to 10:30 PM) ##
TIME_START='0630'
TIME_STOP='2230'
## Let's get some information on the current system ##
current_time="$(date +%H%M)"
create_ap_lines_nb=$(create_ap --list-running | wc -l)
if [[ $((10#${current_time})) -gt $((10#${TIME_START})) && $((10#${current_time})) -lt $((10#${TIME_STOP})) ]]; then
if [[ ${create_ap_lines_nb} -eq 2 ]]; then
create_ap \
${INTERFACE} ${INTERFACE} \
${SSID} ${PASSPHRASE} \
-c ${CHANNEL} \
--freq-band ${FREQUENCY} \
--country ${COUNTRY_FLAG} \
--daemon > /dev/null 2>&1
sleep 5
fi
list_devices="$(create_ap --list-clients ap0)"
if [[ -n ${list_devices} && ${list_devices} != "No clients connected" ]]; then
echo -e "${current_time} : ${list_devices}\\n" >> /root/wifiDevices.log
fi
elif [[ ${create_ap_lines_nb} -gt 2 ]]; then
create_ap --stop ap0 > /dev/null 2>&1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment