INNER CODE UNIT · Python
run_ipt6_cmd
ab77/netflix-proxy · auth/auth.py:44
def run_ipt6_cmd(ipaddr, op):
iface = get_iface()
web.debug('DEBUG: public iface=%s ipaddr=%s' % (iface, ipaddr))
ipt_cmd = 'ip6tables -t nat -%s PREROUTING -s %s/128 -i %s -j ACCEPT -v && ip6tables-save > /etc/iptables/rules.v6' % (op, ipaddr, iface)
web.debug('DEBUG: ipaddr=%s, op=%s, ipt_cmd=%s' % (ipaddr, op, ipt_cmd))
p = Popen(ipt_cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
output, err = p.communicate()
rc = p.returncode
return rc, err, output
def get_client_public_ip():
return web.ctx.env.get('HTTP_X_FORWARDED_FOR') or web.ctx.get('ip', None)
def get_iface():
cmd = "ip route | grep default | awk '{print $5}' | head -n 1"
web.debug('DEBUG: getting public iface name cmd=%s' % cmd)