# Lets bind correct IP address for the listening socket and outgoing connections.
# To do this we have to figure out an name of interface with IPv4 address to bind to: [qvs0|bond0|eth0|tun0]
method.insert = cfg.interface.bind, simple|private, \
"execute.capture_nothrow=sh,-c,\"$cat=\\\"bindif=`getcfg rtorrent bind_interface_name -f /etc/config/qpkg.conf` \
|| bindif=`route | grep '^default' | grep -o '[^ ]*$'` ; \
ifconfig 2>/dev/null | grep -q $bindif 2>/dev/null \
&& echo -n $bindif \
|| echo -n $(route | grep '^default' | grep -o '[^ ]*$') \\\"\""
print = (cat, "Iface : Default network interface : ", (cfg.interface.bind))
# Get IPv4 address of a given interface
method.insert = get_interface_ipv4_address, simple|private, \
"execute.capture=sh,-c,\"$cat=\\\"setcfg rtorrent bind_interface_config_ipv4_addr $(ip -o -4 addr show \\\",$argument.0=,\\\" | grep -Po 'inet \\\\\\\\\\K[\\\\\\\\\\d.]+') -f /etc/config/qpkg.conf \
&& echo -n $(getcfg rtorrent bind_interface_config_ipv4_addr -f /etc/config/qpkg.conf)\\\"\""
# The IP address the listening socket and outgoing connections is bound to. (bind)
# (Refresh every 10 seconds)
schedule2 = set_bind_address, 0, 10, \
"branch=((cfg.interface.bind)), \
((network.bind_address.set,(get_interface_ipv4_address,(cfg.interface.bind))))"
#print = (cat, "Bind IP: Get def interface IPv4addr: ", (get_interface_ipv4_address,(cfg.interface.bind)))
print = (cat, "Bind IP: Current interface IPv4addr: ", (network.bind_address))
schedule2 = print_bind_address, 0, 10, "print = (cat, \"Bind IP: Current interface IPv4addr: \", (network.bind_address))"
# The ip address reported to the tracker
# Get public IP address without the need of having dynamic DNS service, also works from behind NAT, through tunnel
method.insert = get_public_ip_address, simple|private, \
"execute.capture_nothrow=sh,-c,\"$cat=\\\"setcfg rtorrent bind_interface_public_ipv4_addr \$(\
curl -sL --connect-timeout 2 --interface \\\", (cfg.interface.bind), \\\" http://ipinfo.io/ip || \
curl -sL --connect-timeout 2 --interface \\\", (cfg.interface.bind), \\\" http://obj.qnapclub.pl/app/net/ip.php || \
curl -sL --connect-timeout 5 --interface \\\", (cfg.interface.bind), \\\" http://icanhazip.com || \
curl -sL --connect-timeout 5 --interface \\\", (cfg.interface.bind), \\\" http://ipinfo.io/ip || \
curl -sL --connect-timeout 10 --interface \\\", (cfg.interface.bind), \\\" http://obj.qnapclub.pl/app/net/ip.php || \
curl -sL --connect-timeout 10 --interface \\\", (cfg.interface.bind), \\\" http://ifconfig.co || \
echo -n 127.0.0.1) -f /etc/config/qpkg.conf \
&& echo -n $(getcfg rtorrent bind_interface_public_ipv4_addr -f /etc/config/qpkg.conf)\\\"\""
# The IP address reported to the tracker. (ip) This handles dynamic IP's as well. Fallback to localhost for safety reasons.
# (Refresh your outgoing IP every (10)+(10+15+20)+5 extra seconds)
schedule2 = ip_tick, 0, 60, "network.local_address.set=(get_public_ip_address);print = (cat, \"New Public IP address: \", (network.local_address))"