TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Tiny, fast, and free API to geolocate IP addresses

144 pointsby whatl3yover 5 years ago

13 comments

hombre_fatalover 5 years ago
<p><pre><code> const realClientIpAddress = (req.headers[&#x27;x-forwarded-for&#x27;] || req.ip || &quot;&quot;).split(&#x27;,&#x27;) const ip = realClientIpAddress[realClientIpAddress.length - 1] </code></pre> X-Forwarded-For is appended-to for every proxy the request passes through. You want the first IP address, not the last one.<p>Example, if your app was on Heroku behind Cloudflare, the request will look like this:<p>IP: &lt;Heroku&#x27;s load balancer addr&gt;<p>X-Forwarded-For: &lt;Real user addr&gt;, &lt;Cloudflare addr&gt;<p>Your code, as written, will be geolocating the Cloudflare node.
评论 #21744150 未加载
freegeoipover 5 years ago
I run <a href="https:&#x2F;&#x2F;freegeoip.app" rel="nofollow">https:&#x2F;&#x2F;freegeoip.app</a> for some time now, if anyone is interested in a free hosted solution.
评论 #21746943 未加载
jedbergover 5 years ago
The problem with geoip is that the free services will never be as good as the paid services, and the paid ones aren&#x27;t all that accurate either.<p>For just about every geoip use case, there is a better solution. Namely, almost every modern phone and desktop is capable of providing it&#x27;s location, and is more accurate than any geoip database.<p>The main issue is that people can make their device lie about it&#x27;s location, so if you&#x27;re using geoip for security (say you&#x27;re a streaming service) then that&#x27;s about the only valid use case, and that only exits because studios still want to live in a world where borders matter.
评论 #21748083 未加载
评论 #21751272 未加载
chrismellerover 5 years ago
There are easier ways to use MaxMind data without injecting a third party.
评论 #21745105 未加载
评论 #21746412 未加载
aluminussomaover 5 years ago
I see that the underlying IP to Geo data is consolidated by MaxMind. Where does MaxMind get this data? I wish this data was open sourced.
评论 #21744026 未加载
评论 #21744958 未加载
评论 #21753057 未加载
gramakriover 5 years ago
We made a similar app called geoip - <a href="https:&#x2F;&#x2F;git.cloudron.io&#x2F;cloudron&#x2F;geoip" rel="nofollow">https:&#x2F;&#x2F;git.cloudron.io&#x2F;cloudron&#x2F;geoip</a> . It also uses maxmind&#x27;s db. Supports json and jsonp as well. You can try it at <a href="https:&#x2F;&#x2F;geolocation.cloudron.io&#x2F;json" rel="nofollow">https:&#x2F;&#x2F;geolocation.cloudron.io&#x2F;json</a> . Please don&#x27;t use this as a &#x27;service&#x27;, install your own :)<p>BTW, do you use geolite or geolite2 db? The former is getting deprecated next month.
coderholicover 5 years ago
I started IPinfo.io ~6 years (and launched it on HN: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7239333" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7239333</a>). We now serve 20 billion geolocation API requests a month, and roll our own geolocation data (we used to rely on the maxmind data, but have been busy working on improvements to that, and then our own complete data, along with other data sets like IP usage type, company and carrier etc).
评论 #21762514 未加载
kpsychwaveover 5 years ago
GeoIP is pretty accurate at the state&#x2F;country level for most users, but you will run into precision issues at the city level.<p>A bigger problem seems to be that many forget to continuously sync their IP DB with their provider. Your targeting is only as good as your IP -&gt; Geo map.<p>My team built a tool for testing GeoIP implementations here: <a href="https:&#x2F;&#x2F;www.geoscreenshot.com" rel="nofollow">https:&#x2F;&#x2F;www.geoscreenshot.com</a> to get around the issue of testing if it works.
评论 #21754180 未加载
zrailover 5 years ago
If you&#x27;re interested in a service with a free tier and more specific granularity than the MaxMind free database, Geocodio has a pretty nice service. They also have a bunch of different enrichment options that you can tack on if you need things like congressional districts or school districts. It&#x27;s a really nice service.<p><a href="https:&#x2F;&#x2F;www.geocod.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.geocod.io&#x2F;</a><p>(not affiliated, just a fan)
评论 #21745998 未加载
andrewkdinhover 5 years ago
A similar service is Am I Mullvad’s API. Not sure if they use MaxMind, however.<p><a href="https:&#x2F;&#x2F;am.i.mullvad.net&#x2F;api" rel="nofollow">https:&#x2F;&#x2F;am.i.mullvad.net&#x2F;api</a>
lollolol13over 5 years ago
This is pretty awesome. Might have to use this for <i></i><i>various</i><i></i> purposes
jcmontxover 5 years ago
You are a hero
GhettoMaestroover 5 years ago
I always feel a need to state this to folks who are not aware of geolocation and ip addresses: Geolocation based on IP is very unreliable and should be used only for soft-analytics at best.<p>Example: It is not fit for security postures (in theory). One can dump all the CURRENT v4 routes being advertised out of China and block them via blackholes&#x2F;firewalls&#x2F;etc. However immediately after that a rogue operator could hijack a non-China affiliated prefix, use it for badness, and then release the hijacked prefix.<p>Most Geolocation services that are static (point in time) will not detect the above scenario. BGP-based monitoring services will, but that&#x27;s a step up $$$ wise.
评论 #21754320 未加载
评论 #21746652 未加载
评论 #21744538 未加载
评论 #21746168 未加载