{"id":13812441,"url":"https://github.com/heiher/natmap","last_synced_at":"2025-05-14T15:00:33.592Z","repository":{"id":61114085,"uuid":"544053253","full_name":"heiher/natmap","owner":"heiher","description":"TCP/UDP port mapping for full-cone NAT","archived":false,"fork":false,"pushed_at":"2025-05-04T00:43:14.000Z","size":227,"stargazers_count":1596,"open_issues_count":11,"forks_count":119,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-05-12T02:56:38.154Z","etag":null,"topics":["bsd","linux","macos","nat1","port-mapping","tcp","udp","windows"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heiher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-01T14:16:59.000Z","updated_at":"2025-05-10T13:36:48.000Z","dependencies_parsed_at":"2024-01-03T06:27:45.508Z","dependency_job_id":"76d87fe4-d4c5-4b8b-8de4-688d7c1f1856","html_url":"https://github.com/heiher/natmap","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fnatmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fnatmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fnatmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fnatmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heiher","download_url":"https://codeload.github.com/heiher/natmap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254168206,"owners_count":22026117,"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":["bsd","linux","macos","nat1","port-mapping","tcp","udp","windows"],"created_at":"2024-08-04T04:00:51.948Z","updated_at":"2025-05-14T15:00:33.175Z","avatar_url":"https://github.com/heiher.png","language":"C","readme":"# NATMap\n\n[![status](https://github.com/heiher/natmap/actions/workflows/build.yaml/badge.svg?branch=master\u0026event=push)](https://github.com/heiher/natmap)\n[![chat](https://github.com/heiher/natmap/raw/master/.github/badges/telegram.svg)](https://t.me/hellonatter)\n\nThis project is used to establish a TCP/UDP port mapping from an ISP NAT public\naddress to local private address. If all layers of NAT are full cones (NAT-1),\nany host can access internal services through the mapped public address. In bind\nmode, all traffic does not go through this program.\n\n[中文文档](https://github.com/heiher/natmap/wiki)\n\n## How to Build\n\n```bash\ngit clone --recursive https://github.com/heiher/natmap.git\ncd natmap\nmake\n\n# statically link\nmake ENABLE_STATIC=1\n\n# cross compile\nmake CROSS_PREFIX=${cross-toolchain}/bin/x86_64-unknown-linux-\n\n# android\nmkdir natmap\ncd natmap\ngit clone --recursive https://github.com/heiher/natmap.git jni\nndk-build\n\n# windows (msys2)\nexport MSYS=winsymlinks:native\ngit clone --recursive https://github.com/heiher/natmap.git\ncd natmap\nmake LFLAGS=\"-lmsys-2.0 -lws2_32\"\n```\n\n## How to Use\n\n### Usage\n\n```\nUsage:\n natmap [options]\n\nOptions:\n -4                  use IPv4\n -6                  use IPv6\n -u                  UDP mode\n -d                  run as daemon\n -i \u003cinterface\u003e      network interface or IP address\n -k \u003cinterval\u003e       seconds between each keep-alive\n -c \u003ccount\u003e          UDP STUN check cycle (every \u003ccount\u003e intervals)\n -s \u003caddr\u003e[:port]    domain name or address of STUN server\n -h \u003caddr\u003e[:port]    domain name or address of HTTP server\n -e \u003cpath\u003e           script path for notify mapped address\n -f \u003cmark\u003e           fwmark value (hex: 0x1, dec: 1, oct: 01)\n\nBind options:\n -b \u003cport\u003e[-port]    port number range for binding\n                     - \u003c0\u003e: random allocation\n                     - \u003cport\u003e: specified\n                     - \u003cport\u003e-\u003cport\u003e: sequential allocation within the range\n\nForward options:\n -T \u003ctimeout\u003e        port forwarding timeout in seconds\n -t \u003caddress\u003e        domain name or address of forward target\n -p \u003cport\u003e           port number of forward target (0: use public port)\n```\n\n### Bind mode\n\n```bash\n# TCP\nnatmap -s turn.cloudflare.com -h example.com -b 80\n\n# UDP\nnatmap -u -s turn.cloudflare.com -b 443\n```\n\nIn TCP mode, this program will establishs a TCP port mapping in two steps:\n\n1. Establish a connection with the HTTP server from the specified bind port and\nkeep it alive.\n2. Establish a connection with the STUN server from the same port and obtain the\npublic address.\n\nThis program will then call the script specified by the argument to inform the\npublic address after the port mapping is established. The script can update\nthe DNS record for external access.\n\nIn TCP mode on Windows, make sure your application server is bound to the local\nnetwork IP, not to `0.0.0.0` and `::`.\n\nIn UDP mode on Windows, make sure your application server is bound to `0.0.0.0`\nor `::`, not to the local network IP.\n\nPlease note that you need to open the firewall to allow access to the bind port.\n\n#### OpenWrt\n\nGoto Network -\u003e Firewall -\u003e Traffic Rules\n\nAdd a traffic rule:\n\n* Protocol: TCP/UDP\n* Source zone: wan\n* Destination zone: Device (input)\n* Destination port: [bind port]\n* Action: accept\n* Others: keep default values\n\nIf the port binding fails because it is already in use, this program will try\nto find out which local service process occupies the port and enable port reuse\nremotely. This works in Linux kernel 5.6 and later, and needs to run as root.\n\n### Forward mode\n\n```bash\n# TCP\nnatmap -s turn.cloudflare.com -h example.com -b 80 -t 10.0.0.2 -p 80\n\n# UDP\nnatmap -u -s turn.cloudflare.com -b 443 -t 10.0.0.2 -p 443\n```\n\nSimilar to bind mode, this program will listen on bound port, accepts incoming\nconnections, and forward them to target address.\n\nAnother way is to use firewall's DNAT to forward, and this way should uses bind\nmode.\n\n#### OpenWrt\n\nGoto Network -\u003e Firewall -\u003e Port Forwards\n\nAdd a port forward rule:\n\n* Protocol: TCP/UDP\n* Source zone: wan\n* External port: [bind port]\n* Destination zone: lan\n* Internal IP address: 10.0.0.2\n* Internal port: 80\n* Others: keep default values\n\n### Script arguments\n\n```\n{public-addr} {public-port} {ip4p} {private-port} {protocol} {private-addr}\n```\n\n* argv[0]: Script path\n* argv[1]: Public address (IPv4/IPv6)\n* argv[2]: Public port\n* argv[3]: IP4P\n* argv[4]: Bind port (private port)\n* argv[5]: Protocol (TCP/UDP)\n* argv[6]: Private address (IPv4/IPv6)\n\n### IP4P address\n\nThe IP4P address format uses IPv6 special addresses to encode IPv4 addresses and\nports for easy distribution through DNS AAAA records.\n\n```\n2001::{port}:{ipv4-hi16}:{ipv4-lo16}\n```\n\n## Contributors\n* **abgelehnt** - https://github.com/abgelehnt\n* **hev** - https://hev.cc\n* **mike wang** - https://github.com/mikewang000000\n* **muink** - https://github.com/muink\n* **tianling shen** - https://github.com/1715173329\n* **xhe** - https://github.com/xhebox\n\n## License\nMIT\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiher%2Fnatmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheiher%2Fnatmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiher%2Fnatmap/lists"}