1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script Help Needed to Ignore MAC Addresses

Discussion in 'Tomato Firmware' started by joelinkup, Nov 17, 2007.

  1. joelinkup

    joelinkup LI Guru Member

    I have a WRT54GL Router...I use the following Script to show amber when a client is attached and white when there is client activity and dark when there is no client...I use the IGNORE a MAC Address section to ignore my Print Server that is always a client, otherwise, there is always activity...I need to IGNORE 3 Cameras also...So the script needs to be modified to IGNORE 4 MAC Addresses instead of just 1...I have tried for many hours but I cannot get the job done...Any help would be greatly appreciated...Thanks a lot...

    #!/bin/sh
    I=`nvram get wl0_ifname`
    while sleep 1; do
    minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff)
    if [ -n "$minusbridge" ] ; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
    LED="amber off white on"
    PXFER=$XFER
    else
    LED="amber on white off"
    fi
    else
    LED="amber off white off"
    fi
    if [ "$LED" != "$PLED" ]; then
    led $LED
    PLED=$LED
    fi
    done

    Note:
    Substitute aa-ff with the MAC Address to Ignore...
     
  2. acidmelt

    acidmelt LI Guru Member

    just create a few more variables like $minusbridge (eg. minusbridge1/2/3) that hold the value of grepping assoclist for the right MAC's and change the conditional test to "[[ -n "$minusbridge1" && -n "$minusbridge2" ... etc. ]];".

    edit: seems like busybox's [[ doesnt work as expected, try [ -n "$minusbridge1" -a -n "$minusbridge2" -a -n "$min" ... ]; instead.
     
  3. PeterT

    PeterT Network Guru Member

    Try changing the
    Code:
    minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff)
    
    to
    Code:
      minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v gg:hh:ii:jj:kk | grep -v ll:mm:nn:oo:pp | grep -v qq:rr:ss:tt:uu)
    
    where you add in as many "| grep -v mac_address" as you need.

    Code:
    #!/bin/sh
    I=`nvram get wl0_ifname`
    while sleep 1; do
      minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v gg:hh:ii:jj:kk | grep -v ll:mm:nn:oo:pp | grep -v qq:rr:ss:tt:uu)
      if [ -n "$minusbridge" ] ; then
        XFER=`ifconfig $I|grep bytes`
        if [ "$XFER" != "$PXFER" ]; then
          LED="amber off white on"
          PXFER=$XFER
        else
          LED="amber on white off"
        fi
      else
        LED="amber off white off"
      fi
      if [ "$LED" != "$PLED" ]; then
        led $LED
        PLED=$LED
      fi
    done
    
    
     
  4. acidmelt

    acidmelt LI Guru Member

    wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v gg:hh:ii:jj:kk - that would pipe the output of grep -v aa:bb:cc:dd:ee:ff to the second grep. You could use the following code though:
    Code:
    minusbridge="$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff)$(wl assoclist | grep -v aa:bb:cc:dd:ee:xx)$(wl assoclist | grep -v aa:bb:cc:dd:ee:yy)"
    
     
  5. PeterT

    PeterT Network Guru Member

    But I WANT to pipe the output of one grep to the next... The -v switch says to EXCLUDE matching lines; NOT include them...

    So by concatenating MUTLIPLE grep -v's the first one fillters out string1, then the second filters out the string2's etc, so the final result is the input file without ANY of the string1, striing2 etc.....

    Code:
    Usage: grep [-ihHnqvsEABC] PATTERN [FILEs...]
    
    Search for PATTERN in each FILE or standard input.
    
    Options:
            -H      prefix output lines with filename where match was found
            -h      suppress the prefixing filename on output
            -i      ignore case distinctions
            -l      list names of files that match
            -L      list names of files that do not match
            -n      print line number with output lines
            -q      be quiet. Returns 0 if PATTERN was found, 1 otherwise
            -v      select non-matching lines
            -s      suppress file open/read error messages
            -c      only print count of matching lines
            -f      read PATTERN from file
            -e      PATTERN is a regular expression
            -F      PATTERN is a set of newline-separated strings
            -E      PATTERN is an extended regular expression
            -A      print NUM lines of trailing context
            -B      print NUM lines of leading context
            -C      print NUM lines of output context
    
     
  6. joelinkup

    joelinkup LI Guru Member

    The information from PeterT seems to work PERFECTLY...I tell you I tried that same thing yesterday but I could not get it to work...But I was cutting and pasting so perhaps I got some junk in there...This time I keyed it all in...THANKS to PeterT as, in the end, he got the job done...I really appreciate the help from everyone...Now I have one more thought...As it stands when there is NO Client the Cisco LED is dark...I would like it to BLINK Orange when there is NO Client...The line at LED="amber off white off" is where the modification needs to be made...I tried some looping with a counter but again I failed...Perhaps you fellows could help me with this one more modification...Thanks...

    #!/bin/sh
    I=`nvram get wl0_ifname`
    while sleep 1; do
    minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff)
    if [ -n "$minusbridge" ] ; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
    LED="amber off white on"
    PXFER=$XFER
    else
    LED="amber on white off"
    fi
    else
    LED="amber off white off"
    fi
    if [ "$LED" != "$PLED" ]; then
    led $LED
    PLED=$LED
    fi
    done
     
  7. acidmelt

    acidmelt LI Guru Member

    Whoops, sorry :) shouldve looked up the -v switch first.. my solutions arent even valid in that case as I was thinking the opposite way.
     
  8. yaqui

    yaqui LI Guru Member

    Try this:
    Code:
    #!/bin/sh
    I=`nvram get wl0_ifname`
    while sleep 1; do
    asslist=`wl assoclist`
    minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff)
        while [ "$asslist" == "" ] ; do
                 led amber off white off
                 sleep 1
                 led amber on white off
                 minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff)
       done
    if [ -n "$minusbridge" ] ; then
       XFER=`ifconfig $I|grep bytes`
       if [ "$XFER" != "$PXFER" ]; then
          LED="amber off white on"
          PXFER=$XFER
       else
       LED="amber on white off"
       fi
    else
    LED="amber off white off"
    fi
    if [ "$LED" != "$PLED" ]; then
       led $LED
       PLED=$LED
    fi
    done
     
  9. joelinkup

    joelinkup LI Guru Member

    The FIRST Script works PERFECTLY. The SECOND Script you just did does NOT work. The Amber Blinking occurs ALL the time. It never breaks out of the loop. ALSO, you may have the loop in the wrong spot because it is the <<< LED=amber off white off >>> area where the problem is. I tried moving the loop to that area but I still could not get it to break out. Any further help would be greatly appreciated. I know, it all takes time and people are busy. Thanks a lot...

    FIRST...WORKS PERFECTLY...
    Script where Client There = Amber Cisco LED, Client Active = White Cisco LED, No Client = Dark Cisco LED, and where 3 MAC Addresses are Ignored...

    #!/bin/sh
    I=`nvram get wl0_ifname`
    while sleep 1; do
    minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff)
    if [ -n "$minusbridge" ] ; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
    LED="amber off white on"
    PXFER=$XFER
    else
    LED="amber on white off"
    fi
    else
    LED="amber off white off"
    fi
    if [ "$LED" != "$PLED" ]; then
    led $LED
    PLED=$LED
    fi
    done

    -------------------------------------------------------------------

    SECOND...DOES NOT WORK...(Blinking NEVER Stops)...
    Script where Client There = Amber Cisco LED, Client Active = White Cisco LED, No Client = Amber Blinking Cisco LED, and where 3 MAC Addresses are Ignored...

    #!/bin/sh
    I=`nvram get wl0_ifname`
    while sleep 1; do
    asslist=`wl assoclist`
    minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff)
    while [ "$asslist" == "" ] ; do
    led amber off white off
    sleep 1
    led amber on white off
    done
    if [ -n "$minusbridge" ] ; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
    LED="amber off white on"
    PXFER=$XFER
    else
    LED="amber on white off"
    fi
    else
    LED="amber off white off"
    fi
    if [ "$LED" != "$PLED" ]; then
    led $LED
    PLED=$LED
    fi
    done
    --------------------------------------------------------------------
     
  10. PeterT

    PeterT Network Guru Member

    Code:
    #!/bin/sh
    I=`nvram get wl0_ifname`
    while sleep 1; do
      minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff)
      while [ "$minusbridge" == "" ] ; do
        led amber off white off
        sleep 1
        led amber on white off
        minusbridge=$(wl assoclist | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff | grep -v aa:bb:cc:dd:ee:ff)
      done
    
      if [ -n "$minusbridge" ] ; then
        XFER=`ifconfig $I|grep bytes`
        if [ "$XFER" != "$PXFER" ]; then
          LED="amber off white on"
          PXFER=$XFER
        else
          LED="amber on white off"
        fi
      else
        LED="amber off white off"
      fi
      if [ "$LED" != "$PLED" ]; then
        led $LED
        PLED=$LED
      fi
    done
    
    What we're doing is reevaluating the list of associated MAC address INSIDE the loop that blinks the led's.

    Previously, we were getting the list of associated devices ONCE ( asslist=`wl assoclist` ) and then retrieving that SAME set of devices each time inside the blink loop ( while [ "$asslist" == "" ] ; do ). At no point inside that loop did we ever change the contents of asslist so of course, it would loop for blinking ever :)
     
  11. joelinkup

    joelinkup LI Guru Member

    The most recent corrected coding for the blinking Cisco LED works PERFECTLY. Now everyone has a broad choice of ways to use the LED to indicate Client There or Client Active or No Client. I want to THANK Low-WRT for getting me started, Yaqui for the initial coding and PeterT for the cleanup work and final coding. This is GREAT and I truly appreciate the effort and time spent by ALL the people involved.

    I am still not totally familiar with the procedures of posting on this forum so I have one forum question to ask. Why is it that when I post my content it has a White background and all the text is pushed to the left while others is in a Blue Box where the proper indentations are maintained. Again, Thanks for all the GREAT work.
     
  12. PeterT

    PeterT Network Guru Member

    The method I use for posting code is to use [noparse]
    Code:
    the script
      with indents
    [/noparse]markers to get this effect
    Code:
    the script
      with indents
     
  13. yaqui

    yaqui LI Guru Member

    I thought because the first loop was doing the evaluation you would not need to place it in the other loop. I did not test the script and just threw something together.

    Thank you for correcting !
     
  14. joelinkup

    joelinkup LI Guru Member

    I know you people have done A LOT of work on my behalf with script help...And I SINCERELY appreciate it...But I am a greedy old man and back asking for more...:)...

    The situation has now grown to where there are 2 Print Servers and 4 Cameras...I want to be able to look at ONLY the WRT54GL Cisco LED and determine what is going on...Two (2) MAC addresses will be totally IGNORED by the router and the LED will remain dark...Any of Four (4) but not necessarily all four at once other MAC addresses when seen by the router will cause the LED to be steady Orange...When there are ANY other clients accessing the router the LED will be steady White...With this setup I will be able to Ignore the Print Servers...I will be able to see if any of the cameras are plugged in via an Orange LED...and I will be able to see if any other clients are accessing the router via a White LED...

    I do not need a distinction between a client being there and a client sending data...Sending data does not concern me...Being THERE does...I will make the assumption that if they are there they are at some point going to send data...

    Since I have not experienced this setup in practical application I cannot completely grasp how fast these indicators will alert me...So I have one more option I would like to add to this project...I would like the option to have the Orange LED blink instead of being steady OR the White LED blink instead of being steady...I would like to have one script where the LEDS are both steady...and another script where one of the LEDS of my choice is blinking instead of steady...

    I KNOW this is OVER THE TOP in asking for all this...but I have played with it for a week and I am not capable of doing it...so all I can do is ask...But I totally understand if it’s JUST TOO MUCH...There is no harm in asking is my thought…If you feel inclined to give it a go…I appreciate it…

    Thanks...
     

Share This Page