Skip to content

Instantly share code, notes, and snippets.

@grimpy
Created October 18, 2019 16:13
Show Gist options
  • Save grimpy/9f5e19b9b14a6d38a9370088e9676249 to your computer and use it in GitHub Desktop.
Save grimpy/9f5e19b9b14a6d38a9370088e9676249 to your computer and use it in GitHub Desktop.
#!/bin/sh
macs="30:24:32:a9:f8:49 e0:2c:b2:57:45:64"
max="104857600"
for mac in $macs; do
datused=$(nlbw -c csv -g ip,mac | grep "\"$mac"\" | awk '{s+=$4 + S6} END {print s}')
#datused=$(cat /home/Jo/sample2.csv | grep "\"$mac"\" | awk '{s+=$4 + S6} END {print s}')
echo $mac $datused
ip=$(nlbw -c csv -g mac,ip | grep "\"$mac\"" | awk '{print $2}' | tr -d \")
if [ -z "$ip" ]; then
echo "No traffic for $mac"
continue
fi
if [[ "$datused" -gt "$max" ]]; then
echo "limit reached $ip $mac"
if ! iptables -vnL FORWARD | grep "$ip" > /dev/null; then
echo "Adding filter"
iptables -I FORWARD -s "$ip" -j DROP
fi
else
echo "limit not reached $ip $mac"
if iptables -vnL FORWARD | grep "$ip" > /dev/null; then
echo "Removing filter"
iptables -D FORWARD -s "$ip" -j DROP
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment