{"id":13581613,"url":"https://github.com/zhanhb/cidr-merger","last_synced_at":"2026-01-14T16:01:33.439Z","repository":{"id":43760140,"uuid":"199166678","full_name":"zhanhb/cidr-merger","owner":"zhanhb","description":"A simple command line tool to merge ip/ip cidr/ip range, supports IPv4/IPv6","archived":false,"fork":false,"pushed_at":"2022-03-03T09:18:42.000Z","size":1693,"stargazers_count":230,"open_issues_count":0,"forks_count":31,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T10:42:54.502Z","etag":null,"topics":["cidr","cidr-merger","ip-cidr","ip-range","merge"],"latest_commit_sha":null,"homepage":"","language":"Go","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/zhanhb.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}},"created_at":"2019-07-27T13:12:38.000Z","updated_at":"2025-03-11T02:32:29.000Z","dependencies_parsed_at":"2022-09-06T08:51:36.369Z","dependency_job_id":null,"html_url":"https://github.com/zhanhb/cidr-merger","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/zhanhb/cidr-merger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanhb%2Fcidr-merger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanhb%2Fcidr-merger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanhb%2Fcidr-merger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanhb%2Fcidr-merger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhanhb","download_url":"https://codeload.github.com/zhanhb/cidr-merger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanhb%2Fcidr-merger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28425596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T15:24:48.085Z","status":"ssl_error","status_checked_at":"2026-01-14T15:23:41.940Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["cidr","cidr-merger","ip-cidr","ip-range","merge"],"created_at":"2024-08-01T15:02:07.922Z","updated_at":"2026-01-14T16:01:33.422Z","avatar_url":"https://github.com/zhanhb.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# cidr-merger\nA simple utility to merge ip/ip cidr/ip range, support IPv4/IPv6\n\n```\n$ cidr-merger --help\nUsage: cidr-merger [OPTION]... [FILE]...\nWrite sorted result to standard output.\n\nOptions:\n     --batch               batch mode (default if input files supplied or stdin\n                           is not a tty), read file content into memory, then\n                           write to the specified file\n     --cidr                print as ip/cidr (default if not console mode)\n -c, --console             console mode(default if no input files supplied and\n                           stdin is a tty), all input output files are ignored,\n                           write to stdout immediately\n     --empty-policy=value  indicate how to process empty input file\n                             ignore(default): process as if it is not empty\n                             skip: don't create output file\n                             error: raise an error and exit\n -e, --error-if-empty      same as --empty-policy=error\n -h, --help                show this help menu\n     --ignore-empty        same as --empty-policy=ignore\n -k, --skip-empty          same as --empty-policy=skip\n     --merge               sort and merge input values (default)\n     --original-order      output as the order of input, without merging\n -o, --output=file         output values to \u003cfile\u003e, if multiple output files\n                           specified, the count should be same as input files,\n                           and will be processed respectively\n -r, --range               print as ip ranges\n     --simple              output as single ip as possible (default)\n                             ie. 192.168.1.2/32 -\u003e 192.168.1.2\n                                 192.168.1.2-192.168.1.2 -\u003e 192.168.1.2\n -s, --standard            don't output as single ip\n -v, --version             show version info\n```\n\nSample Usage:\n```shell script\n$ echo '1.0.0.1-223.255.255.254' | cidr-merger\n\u003e 1.0.0.1\n  1.0.0.2/31\n  1.0.0.4/30\n  1.0.0.8/29\n  ......\n  1.128.0.0/9\n  2.0.0.0/7\n  4.0.0.0/6\n  8.0.0.0/5\n  16.0.0.0/4\n  32.0.0.0/3\n  64.0.0.0/2\n  128.0.0.0/2\n  192.0.0.0/4\n  208.0.0.0/5\n  216.0.0.0/6\n  220.0.0.0/7\n  222.0.0.0/8\n  223.0.0.0/9\n  ......\n  223.255.255.240/29\n  223.255.255.248/30\n  223.255.255.252/31\n  223.255.255.254\n$ echo '1.1.1.0' \u003e a; \\\n    echo '1.1.1.1' \u003e b; \\\n    echo '1.1.1.2/31' \u003e c; \\\n    echo '1.1.1.3-1.1.1.7' \u003e d; \\\n    cidr-merger -o merge a b c d; \\\n    cat merge; \\\n    rm a b c d merge\n\u003e 1.1.1.0/29\n$ wget -O- \"https://ftp.apnic.net/stats/apnic/`TZ=UTC date +%Y`/delegated-apnic-`TZ=UTC+24 date +%Y%m%d`.gz\" | \\\n    gzip -d | awk -F\\| '!/^\\s*(#.*)?$/\u0026\u0026/CN\\|ipv4/{print $4 \"/\" 32-log($5)/log(2)}' | \\\n    cidr-merger -eo/etc/chinadns_chnroute.txt # update ip on router\n$ #              ^ e: means error if input is empty\n$ echo 'fe80::/10' | cidr-merger -r\n\u003e fe80::-febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff\n$ echo '1.1.1.0' \u003e a; echo '1.1.1.1' | cidr-merger - a; rm a\n$ #                                                ^ -: means standard input\n\u003e 1.1.1.0/31\n```\n\nDifference between standard and simple(default)\n```shell script\n$ echo '1.1.1.1/32' | cidr-merger\n\u003e 1.1.1.1\n$ echo '1.1.1.1/32' | cidr-merger -s\n\u003e 1.1.1.1/32\n$ echo '1.1.1.1/32' | cidr-merger -r\n\u003e 1.1.1.1\n$ echo '1.1.1.1/32' | cidr-merger -rs\n\u003e 1.1.1.1-1.1.1.1\n```\n\nDifference about empty policy\n```shell script\n$ cidr-merger -o txt /dev/null # an empty file named `txt` is created.\n$ cidr-merger -ko txt /dev/null # no file is created, and this program exit with code zero\n$ #            ^ same as `cat /dev/null | cidr-merger --skip-empty --output txt`\n$ cidr-merger -eo txt /dev/null # no file is created, and this program exit with code non zero\n$ #            ^ same as `cat /dev/null | cidr-merger --error-if-empty --output txt`\n$ # option `-e` might be useful when download file from internet and then write to a file\n\n$ # There is no difference if you redirect output to a file such as following\n$ cat /dev/null | cidr-merger -e \u003e txt\n  # file `txt` is created, but this program exit with code non zero\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanhb%2Fcidr-merger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhanhb%2Fcidr-merger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanhb%2Fcidr-merger/lists"}