Geolocate IP address with GeoLite2 database - geoip

I have a list of IP addresses (IPv4 in the form 122.XXX.XXX.XXX) which I want to be assigned to a pair of latitude and longitude coordinates; I would be happy also with a approximate location. I downloaded the free GeoLite2 database (here) but I don't understand how should I proceed, since the IP information in the database is stored as IPv6 (on which I have no experience).
Is there any way to proceed? Should I use drop everything after ::ffff: and then match the rest of the string with my IPv4? Or should I also drop part of my IPv4, which I want to geolocate?

The GeoLite2 database is in hybrid notation to be forwards compatible. While dropping everything after ::ffff: would work, I would recommend the opposite, convert the IPs you get into hybrid notation and then match. (Just add ::ffff: to the front). This should help if you ever have to start supporting IPv6.

Related

How would I go about listing all BTC addresses that have the substring "XYZ" appearing in their address?

I need to list ALL BTC addresses that have the substring "XYZ" appearing in their address. How would I go about doing this ?
I do not have much experience with blockchain and any programming language that could achieve it would be good for me.
It depends on what you mean by "All addresses". If someone creates an address, but no Bitcoin have been sent to it, then there is no way to know it exists unless that person tells you.
If you mean any address which has been sent Bitcoin, then you have to either scan the entire blockchain and encode all scriptPubKeys in every transaction and store it in a searchable database. You could use a service like a block explorer which has already done this, to search for addresses with that substring, but that will probably be an expensive search which might not be possible, because APIs don't typically allow for that type of search.
I would recommend getting a block explorer running locally and then implement your own query using the local transaction database. This will take a while to sync and index the entire blockchain by address.

How to validate Top Level Domain of an email address?

Let's say I have a contact form where a user can enter his email address along with his other contact details. I need to check the validity of Generic top level domain or top level domain of the email address. An example:
scarlet.1992#examplemail.paris
I need to check if .paris is a valid top level domain.
Please refer to this link for the list of domains available, which gives a number around 1200. Storing the domain names in a local table and searching is not an option since new domains are being introduced everyday.
Please let me know if there is any web service or free API available for this, or there is any other way to validate the email address.
The simplest way to find out whether a domain exists is to check whether it has a name server.
Considering that a TLD costs around $100,000 it is very likely that every one that is purchased is in use. Also, if it doesn't have a name server, you can't send anything to it anyway.
Using dig you can run
dig NS +short paris
which will give
h.ext.nic.fr.
d.nic.fr.
g.ext.nic.fr.
f.ext.nic.fr.
whereas
dig NS +short adsfadfs
returns nothing.
There is nothing wrong with storing a list of TLDs locally when you need a quick answer for client-side validation or don't want to consume network resources for a reverse DNS lookup.
Email addresses from newer TLDs are extremely rare for most use cases. I update my list about once per year and find that it's good enough.

How to find historical geolocation for an IP address, perhaps using maxmind?

I was wondering if there is any way to find historical geolocation IP information? Everything I've been able to find discusses current data, but I've been unable to find any way to query a service or DB to, for example, look for information on an IP from a few years ago.
I found this article titled 'How to perform historical IP geolocation lookups' and it does mention maxmind as a potential tool for availability of historical versions but it doesn't mention how to access this data.
Looking through the maxmind api docs I can't seem to find any way to query by date either.
How could one go about finding the location of an IP at a given time in the past? (Extreme accuracy not necessary, an example would be Find the country of this IP address in 2012)
Perhaps there is an easier solution, but it seems that you can download quite a few (not all) old versions of the MaxMind database via the Wayback Machine. For example, this shows the snapshots they have of the binary database. For the CSV files, you'd need to look up the snapshots for specific filenames, and manually change the filenames to the desired 1st-of-month date. For example, here's one.
That said, these posts seem to suggest that IP ranges aren't reassigned to different geographies very often--might not be necessary to worry about getting old versions of the database:
https://serverfault.com/questions/286025/historical-ip-geo-location
https://serverfault.com/questions/59167/how-often-do-ip-blocks-get-reassigned-to-different-regions

django : about subnet address range query

Hello all,
I am working with mysql & django.
I need some time to query of IP address range.
example: 10.25.239.0/26
but, I don't have any idea.
Could you help me?
There are a number of libraries for dealing with IP addresses. We used CIDR Block Converter with a few tweaks. There's also Python ip-tools and several others.

how to get country name and/or code by IP address?

Sorry for so noobish question but how can I do it with C++? I need to get country names and their 2-letter or 3-letter ISO codes (or whatever it's called) using a given IP address. Is there any way to do this easily?
The only two ways I found are to use GeoIP C library or to download a free database but is there something more dynamic? I mean, is there a free web-service with up-to-date db I can utilize for my purpose using curl or something?
Thanks in advance.
MaxMind.com exposes a set of web services for geolocation. They're not free, but cheap per lookup.
One of my clients uses their city-level lookup service, with each result cached for a reasonable period (from memory, 2 or 3 weeks), since IP address blocks don't change location that often.
The application also counts the number of actual lookups to send an admin notification when the number remaining in the subscription gets low, so it can be topped up manually.
I also use the downloadable database in several applications, with a scheduled update process to keep it up to date.
http://www.hostip.info provides an API.