Netgate SG-1000 microFirewall

Author Topic: WOL automatically for PLEX. Need help with syntax.  (Read 355 times)

0 Members and 1 Guest are viewing this topic.

Offline yakboyslim

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: WOL automatically for PLEX. Need help with syntax.
« Reply #15 on: February 02, 2018, 04:49:59 pm »
IT WORKS! (mostly...)

Had to fix a lot of syntax (shellcheck.net helped a ton) and switch my line break style from windows to unix.

Code: [Select]
#!/bin/sh
TARGET='192.168.1.200'
MAC='00:25:64:b8:33:85'
INTERVAL=2
NUMP=1
OLD_LINE=$( clog /var/log/filter.log | grep "1497674444" | tail -1 )
echo "Found this $OLD_LINE"
while true
do
    # Only care about new lines since the script last ran
    NEW_LINE=$( clog /var/log/filter.log | grep "1497674444" | tail -1 )
    echo "New $NEW_LINE"
    if [ "$NEW_LINE" != "$OLD_LINE" ]
    then
        echo "NEW TRAFFIC"
        RET=$( ping -c 1 -W 1 192.168.1.200 | awk '/packets received/ {print $4}' )
        if [ "$RET" -ne "$NUMP" ]
        then
            # Guess it's sleeping. Send WoL.
            echo "WOL. Line was $NEW_LINE"  >> /var/log/wol
            wol -i $TARGET $MAC
            # Could sleep for 20 minutes I guess...I mean, there's no real reason to check again.
            # Whatever...10 seconds is fine.
            sleep 1200
        fi
    fi
    echo "WAITING"
    OLD_LINE=$( clog /var/log/filter.log | grep "1497674444" | tail -1 )
    sleep $INTERVAL
    echo "Old $OLD_LINE"
done

It works exactly like it should and wakes my computer no problems when accessed from WAN. Plex is ready in about 10 seconds. I plan to do some other automation (send WOL packet when the living room tv is turned on) so that we don't see that 10 second wait usually.

When I try to access Plex from a device on my network it doesn't work, and double checking it does not appear I have a firewall rule that is tagging that traffic effectively.

Any ideas? Right now I am looking for LAN traffic with a destination port of 32400-32450 which should capture all the ports. I get my LAN/WAN, source/destinations mixed up all the time though.

Online johnpoz

  • Hero Member
  • *****
  • Posts: 15177
  • Karma: +1414/-206
  • Not a pfSense employee, they cannot fire me...
    • View Profile
Re: WOL automatically for PLEX. Need help with syntax.
« Reply #16 on: February 02, 2018, 07:40:20 pm »
why would you have a range of ports?  Do you have 50 plex servers?  Plex by default is port 32400, that is the only port it would be listening on.  You get what mixed up source/dest?
- An intelligent man is sometimes forced to be drunk to spend time with his fools.
- Please don't PM me for personal help
- if you want to say thanks applaud or https://www.freebsdfoundation.org/donate/
1x SG-2440 2.4.2-RELEASE-p1 (work)
1x SG-4860 2.4.2-RELEASE-p1 (home)

Offline yakboyslim

  • Newbie
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: WOL automatically for PLEX. Need help with syntax.
« Reply #17 on: February 02, 2018, 08:11:57 pm »
I just re-read my last post and it is not even close to clear, so I apologize for that.

I read somewhere that Plex used 32410-32414 or so for network discovery, I think. I figured I would just set a range and catch it all in there.

Traffic from a device on my local network to my Plex device would be going to that port as the destination on LAN correct?

If both these devices are on the same switch, they might be communicating directly there. Would the router see that traffic for the purposes of firewall rules? I would think so, especially if the Plex server is sleeping and the client has to "look" for it.

Online johnpoz

  • Hero Member
  • *****
  • Posts: 15177
  • Karma: +1414/-206
  • Not a pfSense employee, they cannot fire me...
    • View Profile
Re: WOL automatically for PLEX. Need help with syntax.
« Reply #18 on: February 02, 2018, 08:24:36 pm »
If you have a network 192.168.x/24 lets call it - and your on 192.168.x.100 and plex is on 192.168.x.101 - no pfsense would never see that traffic.  The only thing plex might have to do is resolve plex.whatever.tld your using to 192.168.x.101

Yes if your .100 box is talking to your .101 plex server the dest would be 32400.. That is IT.. and the source would be whatever random high port your client is using for that session.. Something above 1024 and below 65515..

The only time pfsense would be involved in the traffic is if it was routing it.. so clients on 192.168.x/24 while your plex is on 192.168.y/24
- An intelligent man is sometimes forced to be drunk to spend time with his fools.
- Please don't PM me for personal help
- if you want to say thanks applaud or https://www.freebsdfoundation.org/donate/
1x SG-2440 2.4.2-RELEASE-p1 (work)
1x SG-4860 2.4.2-RELEASE-p1 (home)