We’ll use the built-in read command to extract the comma-separated values of $record, such as $network, $geoname_id, $latitude, $longitude, and others.The variable $record is not an array but a string whose content is a row of GeoLite2-City-Blocks-IPv4.csv.To insert the contents of GeoLite2-City-Blocks-IPv4.csv into an array, we’ll use the built-in readarray command. Which Databases Do We Need?īefore proceeding further, let’s understand how we’ll code some nodes of the previous flowchart: This gives us approximately 4.3-0.6=3.7 billion IPv4 addresses, the same amount in GeoLite2. We must subtract 600 million reserved IPs that aren’t available for public routing from that theoretical number. In fact, since an IPv4 address is a 32-bit number, the total number of possible addresses is 2^32, which equals about 4.3 billion. However, our Bash code can be easily adapted to IPv6 addresses.Īs of January 2023, GeoLite2 contains 3,343,938 IPv4 CIDRs, corresponding to the worldwide coverage of 3,689,264,895 IPv4 addresses (not officially documented). We’ll focus on IPv4 only to avoid cumbersome scripting. In this tutorial, we’ll see how to look up the geolocation of an IP address in the Linux terminal using a local copy of MaxMind’s free GeoLite2 databases and a Bash script. However, we may prefer a locally hosted and manually inspectable database to avoid relying on external services. Many web pages and RESTful services provide data about an IP address, including geolocation.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |