Skip to content

Instantly share code, notes, and snippets.

@LogIN-
Created October 21, 2015 15:35
Show Gist options
  • Select an option

  • Save LogIN-/4f5ff61d7d29e9d56a74 to your computer and use it in GitHub Desktop.

Select an option

Save LogIN-/4f5ff61d7d29e9d56a74 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check new IPv4 addresses
# If address is not in iptables add rule
IPLISTV4=$(host maps.googleapis.com | grep -E 'has address' | awk '{print $4}')
for x in $IPLISTV4
do
$(iptables -L -nv | grep "$x" >> /dev/null)
if [[ "$?" -ne '0' ]]; then
$(iptables -I OUTPUT -p tcp -m tcp -d "$x" -m state --state NEW -j ACCEPT)
fi
done
# Check new IPv6 addresses
# If address is not in iptables add rule
IPLISTV6=$(host maps.googleapis.com | grep -E 'has IPv6 address' | awk '{print $5}')
for x in $IPLISTV6
do
$(iptables -L -nv | grep "$x" >> /dev/null)
if [[ "$?" -ne '0' ]]; then
$(iptables -I OUTPUT -p tcp -m tcp -d "$x" -m state --state NEW -j ACCEPT)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment