Identifying country by IP address

前端 未结 13 1034
盖世英雄少女心
盖世英雄少女心 2020-12-01 05:24

Is there a way to figure out the country name just by looking at an IP address? I mean, do countries have specific ranges of IP addresses? For example, Australia can have IP

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 05:50

    No you can't - IP addresses get reallocated and reassigned from time to time, so the mapping of IP to location will also change over time.

    If you want to find out the location that an IP address currently maps to you can either download a geolocation database, such as GeoLite from MaxMind, or use an API like http://ipinfo.io (my own service) which will also give you additional details:

    $ curl ipinfo.io/8.8.8.8
    {
      "ip": "8.8.8.8",
      "hostname": "google-public-dns-a.google.com",
      "loc": "37.385999999999996,-122.0838",
      "org": "AS15169 Google Inc.",
      "city": "Mountain View",
      "region": "California",
      "country": "US",
      "phone": 650
    }
    

提交回复
热议问题