{"id":17179635,"url":"https://github.com/maxmcd/tcp-proxy","last_synced_at":"2025-04-13T16:31:44.657Z","repository":{"id":60605586,"uuid":"365343915","full_name":"maxmcd/tcp-proxy","owner":"maxmcd","description":"A simple tcp proxy written in Go.","archived":false,"fork":false,"pushed_at":"2022-01-12T02:51:06.000Z","size":5,"stargazers_count":21,"open_issues_count":0,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-31T21:42:39.443Z","etag":null,"topics":["golang","proxy","tcp"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/maxmcd/tcp-proxy","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxmcd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-07T20:17:31.000Z","updated_at":"2023-07-14T00:16:32.000Z","dependencies_parsed_at":"2022-10-02T01:40:16.088Z","dependency_job_id":null,"html_url":"https://github.com/maxmcd/tcp-proxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmcd%2Ftcp-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmcd%2Ftcp-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmcd%2Ftcp-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmcd%2Ftcp-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxmcd","download_url":"https://codeload.github.com/maxmcd/tcp-proxy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223597074,"owners_count":17170872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","proxy","tcp"],"created_at":"2024-10-15T00:27:02.013Z","updated_at":"2024-11-07T22:05:23.779Z","avatar_url":"https://github.com/maxmcd.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TCP Proxy\n\nA simple tcp proxy written in go.\n\nUse like:\n\n```bash\n# with docker\ndocker run -p 20000:20000 maxmcd/tcp-proxy tcp-proxy -l 0.0.0.0:20000 -r 100.111.145.101:2000\n\n# install with go\ngo get github.com/maxmcd/tcp-proxy\n\n# and then use it\ntcp-proxy -l 0.0.0.0:20000 -r 100.111.145.101:2000\n```\n\nFull source:\n\n```go\npackage main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"net\"\n)\n\nvar localAddr *string = flag.String(\"l\", \"localhost:9999\", \"local address\")\nvar remoteAddr *string = flag.String(\"r\", \"localhost:80\", \"remote address\")\n\nfunc main() {\n\tflag.Parse()\n\tfmt.Printf(\"Listening: %v\\nProxying: %v\\n\\n\", *localAddr, *remoteAddr)\n\n\tlistener, err := net.Listen(\"tcp\", *localAddr)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfor {\n\t\tconn, err := listener.Accept()\n\t\tlog.Println(\"New connection\", conn.RemoteAddr())\n\t\tif err != nil {\n\t\t\tlog.Println(\"error accepting connection\", err)\n\t\t\tcontinue\n\t\t}\n\t\tgo func() {\n\t\t\tdefer conn.Close()\n\t\t\tconn2, err := net.Dial(\"tcp\", *remoteAddr)\n\t\t\tif err != nil {\n\t\t\t\tlog.Println(\"error dialing remote addr\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdefer conn2.Close()\n\t\t\tcloser := make(chan struct{}, 2)\n\t\t\tgo copy(closer, conn2, conn)\n\t\t\tgo copy(closer, conn, conn2)\n\t\t\t\u003c-closer\n\t\t\tlog.Println(\"Connection complete\", conn.RemoteAddr())\n\t\t}()\n\t}\n}\n\nfunc copy(closer chan struct{}, dst io.Writer, src io.Reader) {\n\t_, _ = io.Copy(dst, src)\n\tcloser \u003c- struct{}{} // connection is closed, send signal to stop proxy\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxmcd%2Ftcp-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxmcd%2Ftcp-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxmcd%2Ftcp-proxy/lists"}