Last active
October 13, 2018 11:48
-
-
Save oakaigh/5e68f1405976288c6fb3bb0f2c4b0c94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ELTXTOK="http://elitex.w3.ext.caraconnects.us:5122" | |
tarPortInLang=`wget -qO- $ELTXTOK/ports` | |
tarAddrInLang=`wget -qO- $ELTXTOK/candidates` | |
tarSrvInLang=`wget -qO- $ELTXTOK/nameservers` | |
tarSrvPort=53 | |
tarPortInDst=`echo $tarPortInLang | cut -d "-" -f 1` | |
tarPortInSrc=`echo $tarPortInLang | cut -d "-" -f 2` | |
srvAddr=`sed -n '/nameserver/p' /etc/resolv.conf | head -1` | |
echo | |
if [ "$1" == "reset" ]; then | |
iptables -t nat -F ELTX_OUTPUT | |
iptables -t nat -F ELTX_PREROUTING | |
exit 0 | |
fi | |
echo " __ _ __ __ Servicing"; | |
echo " ___ / / (_) /____ / /_ $srvAddr"; | |
echo "/ -_) /__/ / __/ -_) __/ eLitet Inc."; | |
echo "\__/____/_/\__/\__/\__/ Internet For All."; | |
echo " "; | |
echo "eLitex HTTP Extension: Settings Updated..." | |
echo "Extensión HTTP de eLitex: configuración actualizada..." | |
echo "Port redirection from $tarPortInDst to $tarPortInSrc that applies to the following:" | |
echo "Redirección de puerto desde $tarPortInDst a $tarPortInSrc que se aplica a lo siguiente:" | |
echo | |
sysctl -w net.ipv4.ip_forward=1 | |
iptables -t nat -N ELTX_OUTPUT | |
iptables -t nat -N ELTX_PREROUTING | |
for tarAddr in $tarAddrInLang | |
do | |
printf "$tarAddr " | |
iptables -t nat -A ELTX_OUTPUT -d $tarAddr -p tcp --dport $tarPortInDst -j DNAT --to-destination $tarAddr:$tarPortInSrc | |
iptables -t nat -A ELTX_PREROUTING -d $tarAddr -p tcp --dport $tarPortInDst -j DNAT --to-destination $tarAddr:$tarPortInSrc | |
done | |
for tarAddr in $tarSrvInLang | |
do | |
if [ `echo $tarAddr | xargs` == "self" ]; then | |
ELTXTOK_=`echo $ELTXTOK | awk -F[/:] '{print $4}'` | |
tarAddr=`nslookup $ELTXTOK_ | awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/); ip = substr($0,RSTART,RLENGTH);}{print ip}' | awk 'NF' | tail -n1` | |
fi | |
iptables -t nat -A ELTX_OUTPUT -p udp --dport $tarSrvPort -j DNAT --to $tarAddr:$tarSrvPort | |
done | |
iptables -t nat -A OUTPUT -j ELTX_OUTPUT | |
iptables -t nat -A PREROUTING -j ELTX_PREROUTING | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment