There are even packages abstracting those away for you.
And there’s also Locus: Geolocation and ASN lookup of IP addresses