Page 1 of 1

scripting network interfaces

Posted: Tue Dec 10, 2013 7:18 pm
by pgcudahy
I've got a router running gargoyle and have another device connected to it by one of the ethernet interfaces. I'd like to control whether the ethernet connection to that device is up or down based on whether my cell phone is present on the lan as well. Something like this

Code: Select all

ping cell phone ip
   if cell phone responds
       bring lan port 1 up
   if cell phone doesn't respond
       bring lan port 1 down
wait 60 seconds
Anyone have an example of something similar I can start from?

Re: scripting network interfaces

Posted: Wed Dec 11, 2013 6:33 pm
by throughwalls
Does pinging your cellphone work?

Doing it every 60 seconds may be a drain on the battery.

Nice idea though!

Re: scripting network interfaces

Posted: Mon May 19, 2014 9:44 am
by throughwalls
Did you ever get this going?

Re: scripting network interfaces

Posted: Tue May 20, 2014 11:10 pm
by ng3700v2
Here's what I've noticed with my iPhone.

Gargoyle will still show my iPhone as a Wireless Connected Host even when my phone has gone into its low-power sleep mode (when I'm not actively using it). However, it won't respond to a ping until I wake it up. I have also noticed that once I go out of wifi range, it will not automatically reconnect to wifi until I try to use my phone again.

You can use this command to get a list active wireless sessions:

Code: Select all

iw dev wlan0 station dump
So just use that command in your script, looking for the MAC address of your phone, and behave accordingly.

Your example would go something like this:

Code: Select all

    iw dev wlan0 station dump
       if cell phone MAC address is listed
           bring lan port 1 up
       if cell phone MAC address is not listed
           bring lan port 1 down
    wait 60 seconds
Hope that helps.