Getting the Location from an Ip Address

Finding Location through IP address Nodejs mongodb

You can utilize GeoIP-lite to get the geodata from the ip address.

var geoip = require('geoip-lite');

var ip = "207.97.227.239";
var geo = geoip.lookup(ip);

console.log(geo);
/*{ range: [ 3479297920, 3479301339 ],
country: 'US',
region: 'TX',
city: 'San Antonio',
ll: [ 29.4889, -98.3987 ],
metro: 641,
zip: 78218 }*/

How to get location of server based on IP address in Python

This is an example of fetching server location using one of the APIs.

There are many others site options such as keycdn, iplocation and more.

import json
import urllib.request

GEO_IP_API_URL = 'http://ip-api.com/json/'

# Can be also site URL like this : 'google.com'
IP_TO_SEARCH = '87.250.250.3'

# Creating request object to GeoLocation API
req = urllib.request.Request(GEO_IP_API_URL+IP_TO_SEARCH)
# Getting in response JSON
response = urllib.request.urlopen(req).read()
# Loading JSON from text to object
json_response = json.loads(response.decode('utf-8'))

# Print country
print(json_response['country'])

How to find location using ip address

You can get the location of your visitor from its IP address. This is a process called geolocation.

Since you need to get the exact location, you must know that its accuracy depends on multiple factors, and all geolocation APIs are not equally accurate. I managed to get the best result with Abstract API (it has free and commercial plans). You query it with a get request, and you receive a JSON response with latitude, longitude, country, city...

AS the comment under your question states, some visitors can hide their real IP by using a VPN service, and among the JSON response, this API can tell you if the IP belongs to a VPN service, so you know if the visitor was hiding his location and IP.

How to get the geographic location using IP Address in asp.net mvc

This should help you - http://freegeoip.net/

freegeoip.net is a public REST API for searching geolocation of IP addresses and host names.
Send HTTP GET requests to: freegeoip.net/{format}/{ip_or_hostname}. The API supports both HTTP and HTTPS and Supported formats are csv, xml or json.

Getting location details from IP in PHP

$ip = '98.229.152.237';
$xml = simplexml_load_file("http://ipinfodb.com/ip_query.php?ip=$ip");
print_r($xml);

Output:

SimpleXMLElement Object
(
[Ip] => 98.229.152.237
[Status] => OK
[CountryCode] => US
[CountryName] => United States
[RegionCode] => 33
[RegionName] => New Hampshire
[City] => Manchester
[ZipPostalCode] => 03103
[Latitude] => 42.9403
[Longitude] => -71.4435
[Timezone] => -5
[Gmtoffset] => -5
[Dstoffset] => -4
)

Location and region finding from the user ip address

This is because my be freegeoip.net does not have complete region information for IP 117.253.168.187.
I have also tried lots of ip to location but only paid one works fine. You may use http://www.ip2location.com/demo

How to find location of an IP Address Without using APIs?

  1. Use the whois database to find out who the IP is allocated to.
  2. Use DNS to do a reverse lookup on the IP address.
  3. Use traceroute to guess the location based on the routers leading up to the host

As an example, lets look at stackoverflow.com (64.34.119.12)

$ whois 64.34.119.12 | egrep "(OrgName)|(City)|(State)|(Country)"
OrgName: Peer 1 Network Inc.
City: New York
StateProv: NY
Country: US

whois shows us that they're probably in NY, NY.

$ host 64.34.119.12
12.119.34.64.in-addr.arpa domain name pointer stackoverflow.com.

Reverse DNS (PTR record) doesn't help here. However, a lot of ISPs do have region specific reverse DNS entries that can help with this process (especially for dynamically assigned hosts). As an example:

$ host 24.25.195.1
1.195.25.24.in-addr.arpa domain name pointer sndgca-dns-cac-01.san.rr.com.

This host is obviously identified and located by it's PTR record: a Time Warner (Road Runner) caching DNS server in San Diego, CA.

Now, back to the stackoverflow.com locating process:

$ traceroute stackoverflow.com
traceroute to stackoverflow.com (64.34.119.12), 64 hops max, 40 byte packets
ms
(... removed the first few hops ...)
8 ae-6-6.ebr1.Chicago1.Level3.net (4.69.140.189) 30.9 ms 28.855 ms 25.183 ms
9 ae-2-2.ebr2.NewYork2.Level3.net (4.69.132.66) 54.373 ms 54.197 ms 48.171 ms
10 ae-6-6.ebr2.NewYork1.Level3.net (4.69.141.21) 48.250 ms 50.712 ms 51.293 ms
11 ae-62-62.csw1.NewYork1.Level3.net (4.69.148.34) 59.493 ms ae-82-82.csw3.NewYork1.Level3.net (4.69.148.42) 51.694 ms ae-62-62.csw1.NewYork1.Level3.net (4.69.148.34) 58.315 ms
12 ae-3-89.edge1.NewYork1.Level3.net (4.68.16.142) 51.529 ms ae-2-79.edge1.NewYork1.Level3.net (4.68.16.78) 50.77 ms ae-3-89.edge1.NewYork1.Level3.net (4.68.16.142) 50.567 ms
13 10ge-te-1-1.nyc-75bre-dis-2.peer1.net (216.187.115.77) 50.776 ms 51.193 ms 56.166 ms
14 gig2-0.nyc-gsr-b.peer1.net (216.187.123.5) 54.994 ms 58.813 ms 51.794 ms
15 gwny01.stackoverflow.com (64.34.41.58) 54.121 ms 52.65 ms 54.166 ms
16 * * *
(... remaining time outs removed ...)

The traceroute output confirms our suspicion that stackoverflow.com is hosted in NY, NY.

That's one way to tackle geolocation without an API.



Related Topics



Leave a reply



Submit