Skip to content

Instantly share code, notes, and snippets.

@KrisCris
Last active January 3, 2024 13:20
Show Gist options
  • Save KrisCris/425ea3a7b888eb4649b3529d245ab2fd to your computer and use it in GitHub Desktop.
Save KrisCris/425ea3a7b888eb4649b3529d245ab2fd to your computer and use it in GitHub Desktop.
generate_socat_openwrt_config
# configure here
service_name = "sunshine"
dest_ip = "10.0.0.248"
ports = list(range(47984, 47991)) + list(range(47998, 48001)) + [48010]
# do not touch the rest
configurations = []
for port in ports:
# TCP Configuration
tcp_config = f"""config config '{service_name}_{port}'
\toption firewall_accept '1'
\toption enable '1'
\toption remarks '{service_name}-{port}'
\toption protocol 'port_forwards'
\toption proto 'tcp'
\toption listen_port '{port}'
\toption reuseaddr '1'
\toption dest_proto 'tcp4'
\toption dest_ip '{dest_ip}'
\toption dest_port '{port}'\n"""
# UDP Configuration
udp_config = f"""config config '{service_name}_udp_{port}'
\toption firewall_accept '1'
\toption enable '1'
\toption remarks '{service_name}-udp-{port}'
\toption protocol 'port_forwards'
\toption proto 'udp'
\toption listen_port '{port}'
\toption reuseaddr '1'
\toption dest_proto 'udp4'
\toption dest_ip '{dest_ip}'
\toption dest_port '{port}'\n"""
configurations.append(tcp_config)
configurations.append(udp_config)
complete_config = "\n".join(configurations)
print(complete_config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment