-2

I have a rather specific situation where i'm at a bit of a loss on how to do things properly so i figured it was time to ask for help.

Situation is: i have a Raspberry Pi with a 3G modem as well as hostapd and dnsmasq installed. This means that when i'm connected to the hotspot on the Pi i get internet access over 3G.

The setup is going to be used to provide internet access for a boombox to work together with a chromecast audio. Everything works fine and i can connect to the WiFi and play music from spotify - everthing is good. Almost. The cell plan used in the modem is limited to a number of gigabytes - enough for music but not enough for people to forget to get off the wifi when they're not in charge of the music.

What i've done so far is put the Chromecast (and my own phone) on a static IP and set the DHCP scope to exactly 1 address This almost solves my problem except for the obvious design feature that the ip is reserved for the client for as long as the lease is valid. I could set a super short lease time, but that just makes for other problems with people hijacking the ip when trying to connect if someone's already connected.

Ideally what i want to do is clear the lease of a client as soon as it disconnects. Is this possible? Should i do something else? Have i already written too much for anyone to read everything?

I'm at a bit of a loss - what do i do?

Jacob K
  • 101
  • 1

1 Answers1

0

I'll just answer this myself, then.

hostapd_cli can run scripts and interface with hostapd. Together with dhcp_release in dnsmasq_utils you can solve the problem with some scripting:

sudo hostapd_cli -a dhcp_release_script.sh

dhcp_release_script looks like this:

#!/bin/bash
#dhcp-release-script.sh

#Chromecast, My Phone, My Laptop
staticDevicesMac=("" "" "")

if [[ $2 == "AP-STA-DISCONNECTED" ]]
 then
 if [[ ! "${staticDevicesMac[@]}" =~ "${3}" ]]
 then
   dhcp_release $1 10.0.0.20 $3
 fi
fi
Jacob K
  • 101
  • 1