@JohnD5000 edit your post 21 and copy/paste your Code into an 'Insert, Code' box (right beside the Save Icon) in the toolbox.
Remove the "echo $?" line. After that line is executed $? is replaced by the return code of the echo command (which is always 0). So you've effectively just wiped out the return code from the iptables command.Code:else # phone appears disconnected iptables -L FORWARD | grep -q "192.168.1.211-192.168.1.213" # checks to see if rule is there, if so deletes it echo $? if [ $? -eq 0 ]; then
Remove the "echo $?" line. After that line is executed $? is replaced by the return code of the echo command (which is always 0). So you've effectively just wiped out the return code from the iptables command.
Just to elaborate on what Colin mentioned. $? is the return code of the previous command. If a command succeeds it returns a 0 if it fails it returns a 1.
The 'IF [ $? -eq 0 ]' is controlling the next action of the script based on the result of the previous command, because the echo command was returning a 0 the script was trying to remove a rule that was already removed
Maybe add a line after removing the blocking rule to ping the camera, might help wake it up to establish its own connections again also. It shouldn't be losing its wireless connection to your router it just thinks its connection is dead I'm hoping
Hmmm.
Well theres no saying the camera would reply to a ping in the first place, you may have to do more testing to confirm whether it even responds to pings or not.
If toggling the WAN connection restorted the cameras there may be a command you can put in the script for that, but it would interrupt Internet service and if anything went wrong with the script it would require a router reboot likely.
I hate to say this is starting to get beyond my already limited knowledge as it is a cloud based camera which seems to be picky about retaining its connection.
I think if you can live with just blocking the UDP connection for new connection attempts only that may be your best option short of more testing to find a way to force the camera to re-establish a connection to its server after the rule is removed.
#!/bin/sh
if [ $(ping -q -c4 -w5 192.168.1.200 | grep "received" | cut -c 24- | cut -c -1) -ge 2 ]; then # pings 4 times looking for at least 2 replies
iptables -L FORWARD | grep -q "192.168.1.211-192.168.1.213" # checks to see if rule already in place
if [ $? -eq 0 ]; then
exit 0
else
iptables -I FORWARD 1 -p udp -m iprange --src-range 192.168.1.211-192.168.1.213 -j DROP #adds rule to drop .211 .212 .213
fi
else # phone appears disconnected
iptables -L FORWARD | grep -q "192.168.1.211-192.168.1.213" # checks to see if rule is there, if so deletes it
if [ $? -eq 0 ]; then
iptables -D FORWARD -p udp -m iprange --src-range 192.168.1.211-192.168.1.213 -j DROP
else
exit 0 # phone not connected and rules not in place
fi
fi
Looking at Martineaus ARPrefresh script he is just using ping to update the ARP table, the issue is its cache time.
Linux by default has a 60 sec cache time, this can be confirmed by reading the value in /proc/sys/net/ipv4/neigh/ethX/gc_stale_time which is 60.
https://serverfault.com/questions/684380/default-arp-cache-timeout
If you're super concerned about the time between the disconnect and the entry being purged from the table you could lower this value for your wireless interface you connect to, but note I have NO idea what else this would affect on a day to day with your other clients.
My recommendation, just reduce your cron run time from 15 to 1 or 2 mins, the script is so low load it won't hurt anything to run it more often and will only execute the commands if the conditions are met.
No. You want it to look like this:doesn't the 0/10 mean every 10 minutes, ie 0/2 would be every 2 minutes?
No. You want it to look like this:
*/10 * * * * /jffs/scripts/CameraBlock.sh #camerablock#
It says in red underneath that expression: "Non standard! May not work with every cron."Thanks, I went to this site's cron schedule expressions, guess its not same on every system https://crontab.guru/#0/10_*_*_*_*
It says in red underneath that expression: "Non standard! May not work with every cron."
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!