scripting network interfaces

General discussion about Gargoyle, OpenWrt or anything else even remotely related to the project

Moderator: Moderators

Post Reply
pgcudahy
Posts: 2
Joined: Tue Dec 10, 2013 7:11 pm

scripting network interfaces

Post 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?

throughwalls
Posts: 89
Joined: Thu Apr 22, 2010 3:24 pm

Re: scripting network interfaces

Post by throughwalls »

Does pinging your cellphone work?

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

Nice idea though!

throughwalls
Posts: 89
Joined: Thu Apr 22, 2010 3:24 pm

Re: scripting network interfaces

Post by throughwalls »

Did you ever get this going?

ng3700v2
Posts: 32
Joined: Thu Mar 17, 2011 9:02 am

Re: scripting network interfaces

Post 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.

Post Reply