Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #This is a script to run on DD-WRT routers.
- #It will find current "linode connections", and add them to a script that adds then to iptables firewall.
- #RE: http://www.dd-wrt.com/phpBB2/viewtopic.php?p=1073042#1073042
- #This script is basically pieces of eibgrad's scripts, pasted together to do what we want.
- # the _ipt function was taken from another of his scripts: credit to him.
- #Instructions:
- # 1. Copy script to the router / save as a shell script "<script.sh>" [however you want to do this]
- # 2. add permsions to execute: chmod +x <script.sh>
- # 3. Add a cron job to call this every 10min or so: that's all.
- #Also you can restart PMS occasionally to force new connections that can be found
- LINODE_DIR="/jffs/sh" #save to jffs in order to "remember" entries that were previously found
- LINODE_BLOCKER="$LINODE_DIR/linode_blocker.sh"
- PLEXSERVER_IP="192.168.101.125"
- PLEX_USERNAME="user@gmail.com"
- PLEX_PW="thisIsMySecret"
- if [ ! -e $LINODE_BLOCKER ]; then
- mkdir -p $LINODE_DIR
- cat << " EOF" > $LINODE_BLOCKER
- #!/bin/sh
- _ipt() {
- # precede insert/append w/ deletion to avoid dups
- cmd="-I FORWARD -s $PLEXSERVER_IP -d $1 -j REJECT"
- while iptables ${cmd/-[IA]/-D} 2> /dev/null
- do :; done
- iptables $cmd
- }
- EOF
- chmod +x $LINODE_BLOCKER
- sed -i "s:\$PLEXSERVER_IP:$PLEXSERVER_IP:" $LINODE_BLOCKER
- fi
- awk '{i=1; if (NF > 0) do {if ($i ~ /((\d+\.){3}\d+)/) print substr($i,5); i++;} while (i <= NF);}' /proc/net/ip_conntrack | \
- grep -v 192.168 | \
- awk '!x[$0]++ {system("nslookup " $0 " 8.8.8.8")}' | \
- grep "linode" | \
- awk -v blocker="$LINODE_BLOCKER" '{print "_ipt " $3 >> blocker}'
- curl -k -u$PLEX_USERNAME:$PLEX_PW https://plex.tv/services/pubsub/servers | awk -v blocker="$LINODE_BLOCKER" '{i=1; if (NF > 0) do {if ($i ~ /((\d+\.){3}\d+)/) system("if ! $(grep -q " substr($i,7,length($i)-7) " " blocker"); then echo _ipt " substr($i,7,length($i)-7)"; fi"); i++;} while (i <= NF );}' >> $LINODE_BLOCKER
- $LINODE_BLOCKER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement