{"id":48494190,"url":"https://github.com/williamabreu/py-cgnat","last_synced_at":"2026-04-07T11:34:49.658Z","repository":{"id":50681371,"uuid":"267391821","full_name":"williamabreu/py-cgnat","owner":"williamabreu","description":"Python module for generating CGNAT rules using netmap","archived":false,"fork":false,"pushed_at":"2021-10-17T18:25:45.000Z","size":56,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-07T15:21:01.140Z","etag":null,"topics":["cgnat","netmap","python","rfc6598","routeros"],"latest_commit_sha":null,"homepage":"","language":"Python","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/williamabreu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-27T18:07:01.000Z","updated_at":"2024-05-03T15:50:41.000Z","dependencies_parsed_at":"2022-09-26T20:20:54.472Z","dependency_job_id":null,"html_url":"https://github.com/williamabreu/py-cgnat","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/williamabreu/py-cgnat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamabreu%2Fpy-cgnat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamabreu%2Fpy-cgnat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamabreu%2Fpy-cgnat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamabreu%2Fpy-cgnat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/williamabreu","download_url":"https://codeload.github.com/williamabreu/py-cgnat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamabreu%2Fpy-cgnat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31511766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cgnat","netmap","python","rfc6598","routeros"],"created_at":"2026-04-07T11:34:49.527Z","updated_at":"2026-04-07T11:34:49.644Z","avatar_url":"https://github.com/williamabreu.png","language":"Python","readme":"# py-cgnat\n\nPython module for generating CGNAT rules using netmap\n\n## Brief\n\nThis is a Python library and CLI program for generating firewall rules to deploy Carrier-Grade NAT, besides translating a given IP and port to its private address and vice versa. The methodology consists in building netmap rules at 1:32 public-private ratio, mapping a range of 2.000 ports for each client. Works for any netmask, since that follow the 1:32 ratio:\n\n| Private prefix | Public prefix | N. of clients  |\n| :------------: |:-------------:| :-------------:|\n| ... | ... |  ... |\n| /20 | /25 | 4096 |\n| /21 | /26 | 2048 |\n| /22 | /27 | 1024 |\n| /23 | /28 |  512 |\n| /24 | /29 |  256 |\n| /25 | /30 |  128 |\n| /26 | /31 |   64 |\n| /27 | /32 |   32 |\n\n-----------------\n\n## Supported Platforms\n\n- MikroTik RouterOS\n\n## Requirements\n\n- Python 3.7+\n\n-----------------\n\n## How to install it?\n\nInstallation can just being done with ```pip```:\n```bash\npip install pycgnat\n```\n\n## How to use it?\n\n### 1. Command Line Interface\n\nFor **generating** the rules, you can print it in console or save it to a file:\n```bash\npycgnat 100.64.0.0/20 203.0.113.0/25 gen routeros filename.rsc\npycgnat 100.64.0.0/20 203.0.113.0/25 gen routeros\n```\n\nFor **translating** a private IP to its public one, use the ```direct``` option:\n```bash\npycgnat 100.64.0.0/20 203.0.113.0/25 trans --direct 100.64.2.15\npycgnat 100.64.0.0/20 203.0.113.0/25 trans -d 100.64.2.15\n```\n\nFor **translatig** a public IP and port to its private IP correspondent, use the ```reverse``` option:\n```bash\npycgnat 100.64.0.0/20 203.0.113.0/25 trans --reverse 203.0.113.20:13578\npycgnat 100.64.0.0/20 203.0.113.0/25 trans -r 203.0.113.20:13578\n```\n\nThe CLI includes useful **help** command (supported by ```argparse``` framework), so just type:\n```bash\npycgnat --help\npycgnat -h\n```\n\n### 2. Python library\n\nYou can use the functionalities directly in Python lang. Just **import** the wanted module to your program:\n```python\nfrom pycgnat.translator.reverse import cgnat_reverse\n\ndic = cgnat_reverse(privnet, pubnet, IPv4Address('203.0.113.20'), 13578)\nprint(dic['private_ip'])\n```\n\nThe full ```pycgnat```'s documentation is written in the source-code.\n\n## Future works\n\n- Add support for other platfoms (I'm using MikroTik for while, so this is the reason for only supporting it at first version).\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamabreu%2Fpy-cgnat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamabreu%2Fpy-cgnat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamabreu%2Fpy-cgnat/lists"}