Cut Internet temporarily in a device in your LAN

Impressed! I had some functionality on my router similar to this, but it did not work very well.

So I installed the Dinnertime Pluss app ( http://www.dinnertimeapp.com ) on each of the childrens devices. It works ok, but sometimes stops responding.

The kids really hate it, but it was last resort before selling their devices. They really got addicted …

1 Like

What was your work around?

nmap -sn 192.168.1.1/24 >/dev/null && arp -an | grep [redacted mac] | awk ‘{print $2}’ | sed ‘s/[()]//g’

This only loops back to the command line, without greping anything out.

Can’t check sd card crashed again just created whole system again 2 days back :frowning: . Waiting for new power supply and ssd card.

FYI, back when I was using the raspberry Pi’s as my HA system, I used one of these to eliminate power supply issues, outage/brown-outs:

https://www.amazon.com/gp/product/B00MQSMEEE/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

Worked well for me. Ran it for hours!

You could try this in the command line: arp -an
I get this:

[...]
? (192.168.0.86) at <incomplete> on eth0
? (192.168.0.61) at <incomplete> on eth0
? (192.168.0.71) at <incomplete> on eth0
? (192.168.0.34) at <incomplete> on eth0
? (192.168.0.192) at JUST:SOME:MAC:ADD:RESS:HERE [ether] on eth0
? (192.168.0.10) at <incomplete> on eth0
[...]

Later we could see why the grep pipe does not work.

This is just what i’m looking for, but i only need the option to switch OFF and ON the internet connection for the iPads.
Is it enough to just use the new control_internet.sh script and the command line switches?
Per

That’s it @perevers , that should be enough to get it working. I’m assuming that you have arpspoof installed and that the next one-line code gives you an IP address when you type it in the command line (other users found some issues):

nmap -sP ROUTER_ADRS/24 >/dev/null && arp -an | grep CHILD_MAC | awk '{print $2}' | sed 's/[()]//g'

Good luck and don’t hesitate to ask if you get stuck.

Thank you. Haven’t installed arsproof yet and haven’t tried the one-line code yet. Wanted to know if it was possible first. But will let you know when i get it working or need help :grinning:

1 Like

Wow thank you for sharing your project, i will try to set it up :smile:
With 4 kids and iPads it gonna be my best tool ever :wink:

1 Like

@timseebeck, Thanks for this. I appreciate how well you’ve laid this all out but I’m not successfully able to turn off a device’s internet as of yet. Whenever I hit the switch for manual disconnect, it flips back and the log shows

Command failed: /home/homeassistant/.homeassistant/includes/shell_scripts/control_internet.sh my:ma:ca:dd:re:ss on

If I run

nmap -sP ROUTER_ADRS/24 >/dev/null && arp -an | grep CHILD_MAC | awk ‘{print $2}’ | sed ‘s/[()]//g’

I receive the correct IP. I can also manually arpspoof the same device.

Is my /etc/sudoers.d/020_homeassistant_hassbian-scripts file correct? It looks like this:

%homeassistant ALL= NOPASSWD: /usr/local/bin/hassbian-config show *
%homeassistant ALL= NOPASSWD: /usr/local/bin/hassbian-config install *
homeassistant ALL=(ALL) NOPASSWD: /usr/sbin/arpspoof
homeassistant ALL=(ALL) NOPASSWD: /usr/bin/killall arpspoof

Hi @cogneato , since HA says that the command failed, let’s start by trying to run it from the command line. So, I would open a terminal with the homeassistant user and type:

cd /home/homeassistant/.homeassistant/includes/shell_scripts

First, I would check that the device you want to disconnect is connected:

arp -an

A list of IP together with MAC addresses should appear. Then, run the command:

./control_internet my:ma:ca:dd:re:ss on

where my:ma:ca:dd:re:ss is one of the listed by the arp -an command before (Warning! Characters are case sensitive. You have to put the MAC address with lowercase style).
Now check if we are effectively arpspoofing:

ps aux | grep arpspoof

And you should see 3 lines. Something like:

root     26750  0.0  0.6   6244  3096 pts/0    S    10:23   0:00 sudo arpspoof -i eth0 -t 192.168.0.195 192.168.0.1
root     26754  0.0  0.3   2492  1524 pts/0    S    10:23   0:00 arpspoof -i eth0 -t 192.168.0.195 192.168.0.1
homeass+ 27197  0.0  0.4   4272  2100 pts/0    S+   10:33   0:00 grep --color=auto arpspoof

To stop arpspoofing you should type in the command line:

./control_internet.sh my:ma:ca:dd:re:ss off

As for the /etc/sudoers.d/020_homeassistant_hassbian-scripts file, this is what I have:

%homeassistant ALL= NOPASSWD: /usr/local/bin/hassbian-config show *
%homeassistant ALL= NOPASSWD: /usr/local/bin/hassbian-config install *
homeassistant ALL=(ALL) NOPASSWD: /usr/sbin/arpspoof
homeassistant ALL=(ALL) NOPASSWD: /usr/bin/pkill

Please, come back to say if you found issues in the previous steps and I’ll try to do my best to help you.

1 Like

Ok, I am getting “permission denied” when I run

./control_internet.sh my:ma:ca:dd:re:ss on

edit: I can chmod 777 and it works but I don’t understand why I need to do that.

1 Like

FYI: I have it with 755. Not sure if I had to change it or it was already like that because it was a copy-paste from othe file.
Anyway, glad you solve it and thanks for coming back to share what you did.

While testing i am getting error -
. /control_internet xx:xx:xx:xx:xx:xx on
-bash: ./control_internet: No such file or directory.
Permission for the file is -
-rwxr-xr-x 1 homeassistant homeassistant 1248 Jul 2 22:59 control_internet.sh and if i check bash i am getting error -
bash -n control_internet.sh
control_internet.sh: line 17: syntax error near unexpected token elif' 'ontrol_internet.sh: line 17: elif [ “$2” = “off” ]

i am missing something.

It is not finding the file so my guess is that either you forgot the file extension:

./control_internet.sh xx:xx:xx:xx:xx:xx on

or you are not in the directory where the file is.

My guess here is something related with line endings. Please, check this

Tried with extension also and in same directory. Will check elif error. I just copy pasted the script.

will this work if HA is installed on Windows 10?

Hi @ashfaaaa
I really don’t know. First question that comes to my mind is: Is it possible to run shell commands in Windows 10?
If affirmative, we can continue discussing about the next steps.

never used shell commands component before but tried command_line it works. I don’t see why shell command wouldn’t work.