{"id":18952435,"url":"https://github.com/devanshbatham/ip2asn","last_synced_at":"2025-08-10T11:16:49.369Z","repository":{"id":186980710,"uuid":"676101218","full_name":"devanshbatham/ip2asn","owner":"devanshbatham","description":"A utility to quickly map IP addresses to their respective ASN","archived":false,"fork":false,"pushed_at":"2023-08-26T05:32:24.000Z","size":3558,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-23T16:38:01.433Z","etag":null,"topics":[],"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/devanshbatham.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":"2023-08-08T12:39:21.000Z","updated_at":"2025-04-29T10:37:04.000Z","dependencies_parsed_at":"2023-08-08T14:29:34.733Z","dependency_job_id":"b881e633-fcb0-47b4-8017-14944309623e","html_url":"https://github.com/devanshbatham/ip2asn","commit_stats":null,"previous_names":["devanshbatham/ip2asn"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devanshbatham/ip2asn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devanshbatham%2Fip2asn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devanshbatham%2Fip2asn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devanshbatham%2Fip2asn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devanshbatham%2Fip2asn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devanshbatham","download_url":"https://codeload.github.com/devanshbatham/ip2asn/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devanshbatham%2Fip2asn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269713884,"owners_count":24463244,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-08T13:33:25.325Z","updated_at":"2025-08-10T11:16:49.338Z","avatar_url":"https://github.com/devanshbatham.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n    ip2asn\n  \u003cbr\u003e\n\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003eA utility to quickly map IP addresses to their respective ASN\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#installation\"\u003e🏗️ Installation\u003c/a\u003e  \n  \u0026nbsp;\u0026nbsp;\u0026nbsp;\n  \u003ca href=\"#usage\"\u003e⛏️ Usage\u003c/a\u003e\n  \u0026nbsp;\u0026nbsp;\u0026nbsp;\n    \u003ca href=\"#updating-rib-data\"\u003e🔄 Updating RIB Data\u003c/a\u003e \n      \u0026nbsp;\u0026nbsp;\u0026nbsp; \n  \u003ca href=\"#how-it-works\"\u003e📖 How It Works\u003c/a\u003e\n  \u003cbr\u003e\n\u003c/p\u003e\n\n\n![ip2asn](https://github.com/devanshbatham/ip2asn/blob/main/static/ip2asn.png?raw=true)\n\n# Installation\n\n```sh\ngit clone https://github.com/devanshbatham/ip2asn\ncd ip2asn\nsudo chmod +x setup.sh\n./setup.sh\n```\n\n\n\n*Note:* The utility comes pre-packed with trie data, so if you don't wish to update the RIB data, it should work well right off the bat.\n\n# Usage\n\n\n```sh\n(~)\u003e\u003e cat input_ips.txt | ip2asn\n\n74.122.191.97 [AS15211]\n74.122.191.99 [AS15211]\n151.101.65.49 [AS54113]\n162.159.136.66 [AS13335]\n75.2.48.152 [AS16509]\n76.223.91.57 [AS16509]\n80.239.194.78 [AS1299]\n99.86.20.101 [AS16509]\n99.86.20.118 [AS16509]\n```\n\n- With `--json` for JSON output: \n\n```sh\n(~)\u003e\u003e cat input_ips.txt | ip2asn --json\n\n{\n  \"AS1299\": [\n    \"62.115.144.49\",\n    \"62.115.37.34\",\n    \"62.115.57.70\",\n    \"80.239.194.78\"\n  ],\n  \"AS11404\": [\n    \"65.50.201.2\"\n  ],\n  \"AS11696\": [\n    \"69.60.198.202\"\n  ]\n}\n```\n\n\n\n# Updating RIB Data\n\nIf you wish to build the trie yourself or want to update the trie data:\n\n1. By default, `trie_data.json.gz` is saved in the `~/.ip2asn/` folder. So, firstly, delete the `~/.ip2asn` folder.\n2. Run the `get-rib.sh` script.\n3. Build the trie using the `--rib-path` or `--rp` option with the updated RIB data.\n\n```sh\necho \"8.8.8.8\" | ip2asn --rib-path /path/to/processed_rib.txt\n```\n\n\n\n# How It Works\n\nThe `ip2asn` utility employs a trie data structure to map IP address prefixes to their corresponding Autonomous System Numbers (ASN). Each key in the trie represents an IP address prefix, while the corresponding value denotes the AS number that announces these prefixes. The utility checks this trie to find the longest matching prefix for each IP and retrieves its associated ASN.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevanshbatham%2Fip2asn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevanshbatham%2Fip2asn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevanshbatham%2Fip2asn/lists"}