Last active
January 3, 2024 13:20
-
-
Save KrisCris/425ea3a7b888eb4649b3529d245ab2fd to your computer and use it in GitHub Desktop.
generate_socat_openwrt_config
This file contains hidden or 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
# 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