{"id":20376703,"url":"https://github.com/andrebriggs/ip-geo-python","last_synced_at":"2025-10-11T12:43:28.644Z","repository":{"id":150973737,"uuid":"302449625","full_name":"andrebriggs/ip-geo-python","owner":"andrebriggs","description":null,"archived":false,"fork":false,"pushed_at":"2020-10-12T02:09:20.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-04T21:42:21.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/andrebriggs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-08T20:04:44.000Z","updated_at":"2020-10-12T02:09:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"233d08b3-2cc4-42be-8190-61d4cde93f00","html_url":"https://github.com/andrebriggs/ip-geo-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andrebriggs/ip-geo-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fip-geo-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fip-geo-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fip-geo-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fip-geo-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrebriggs","download_url":"https://codeload.github.com/andrebriggs/ip-geo-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrebriggs%2Fip-geo-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007181,"owners_count":26084248,"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-10-11T02:00:06.511Z","response_time":55,"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-15T01:39:12.331Z","updated_at":"2025-10-11T12:43:28.622Z","avatar_url":"https://github.com/andrebriggs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Azure Log Analytics to IP to Geo\n\nThis is a simple example of how to get more accurate location data from Azure Monitor's [Log Analytics](https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/log-query-overview) using [GeoIP2](https://github.com/maxmind/GeoIP2-python). The use of Azure Monitor isn't required, any list of IP addresses will work.\n\n## Requirements\n\n* A GeoLite2 database. You can download a database [here](https://dev.maxmind.com/geoip/geoip2/geolite)\n* A CSV with a list of IP addresses (IPv4 and IPv6 supported)\n\n## Use a Kusto Query (optional)\n\nYou can use Log Analytics feature in Azure Monitor to perform a query that can return IP addresses. Queries use the [Kusto](https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/) langauge.\n\nAn example Kusto query that pulls 12 hours of distinct request IP addresses from an Azure CDN instance is below. Queries can be performed from the Azure Portal or programmatically.\n\n```code\nAzureDiagnostics\n| where TimeGenerated \u003e= now(-12h)\n| where OperationName == \"Microsoft.Cdn/Profiles/AccessLog/Write\" and Category == \"AzureCdnAccessLog\"\n| where isReceivedFromClient_b == true\n| distinct clientIp_s\n```\n\n\n## Running the code\nCreate a virtual environment and install requirements via `pip`.\n\n```console\n$ python3 -m venv env`\n$ pip install -r requirements.txt`\n```\n\nRun \n```console\n$ python geo_from_ip.py (path to IP CSV) (path to Database file)\n```\n\n## Example of output\n```csv\ncountry_code,sub_division,ip_count\nUS,New Jersey,980\nUS,Massachusetts,5\nKR,Seoul,3\nAU,Victoria,1\nHK,Sha Tin,1\nIN,Maharashtra,1\nKR,Gyeonggi-do,1\nTH,Bangkok,1\nTW,Taichung City,1\nTW,Taipei City,1\n```\n\n## Thinking about Privacy Preservation\n\nApparently Log Analytics is [HIPAA compliant](https://azure.microsoft.com/mediahandler/files/resourcefiles/microsoft-azure-compliance-offerings/Microsoft%20Azure%20Compliance%20Offerings.pdf) in the Azure Public and Government Clouds. In this example we are getting data from Azure CDN via Azure Monitor Log Analytics. When clients connect to on a CDN, they should know the privacy policy. If Log Analytics provided an option to disable [IP address](https://docs.microsoft.com/en-us/azure/cdn/enable-raw-logs#raw-logs-properties) logging or at least provide a less privileged view of the log data the privacy posture would be improved. This is especially true for fields such as Healthcare.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrebriggs%2Fip-geo-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrebriggs%2Fip-geo-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrebriggs%2Fip-geo-python/lists"}