Вот, рекомендуемый (по качеству) ресурс по России:
Там нужно по-быстренькому зарегистрироваться (по мэйл) и получить IDE для разных языков.
Меня интересуют там Python и Go (хотя там больше).
Беру в готовом виде неизменно их заготовки...
Модераторы: Olej, adminn, vikos
Код: Выделить всё
olej@R420:~/2023/own.BOOKs$ python
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> impodt dadata
File "<stdin>", line 1
import dadata
^^^^^^
Код: Выделить всё
olej@R420:~/2023/own.BOOKs$ pip install dadata
Defaulting to user installation because normal site-packages is not writeable
Collecting dadata
Downloading dadata-21.10.1-py3-none-any.whl (10 kB)
Collecting httpx
Downloading httpx-0.23.3-py3-none-any.whl (71 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 71.5/71.5 KB 891.8 kB/s eta 0:00:00
Requirement already satisfied: certifi in /usr/lib/python3/dist-packages (from httpx->dadata) (2020.6.20)
Collecting sniffio
Downloading sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting rfc3986[idna2008]<2,>=1.3
Downloading rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)
Collecting httpcore<0.17.0,>=0.15.0
Downloading httpcore-0.16.3-py3-none-any.whl (69 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 69.6/69.6 KB 1.8 MB/s eta 0:00:00
Collecting anyio<5.0,>=3.0
Downloading anyio-3.6.2-py3-none-any.whl (80 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 80.6/80.6 KB 2.0 MB/s eta 0:00:00
Collecting h11<0.15,>=0.13
Downloading h11-0.14.0-py3-none-any.whl (58 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 KB 3.1 MB/s eta 0:00:00
Requirement already satisfied: idna in /usr/lib/python3/dist-packages (from rfc3986[idna2008]<2,>=1.3->httpx->dadata) (3.3)
Installing collected packages: rfc3986, sniffio, h11, anyio, httpcore, httpx, dadata
Successfully installed anyio-3.6.2 dadata-21.10.1 h11-0.14.0 httpcore-0.16.3 httpx-0.23.3 rfc3986-1.5.0 sniffio-1.3.0
Код: Выделить всё
lej@R420:~/2023/own.BOOKs$ python
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dadata
>>> from dadata import Dadata
>>> token = "ef835f86e5405beefe93c60ae0399ac21c89254e"
>>> dadata = Dadata(token)
>>> result = dadata.iplocate("213.159.214.240")
>>> result
{'value': 'г Москва', 'unrestricted_value': '101000, г Москва', 'data': {'postal_code': '101000', 'country': 'Россия', 'country_iso_code': 'RU', 'federal_district': 'Центральный', 'region_fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'region_kladr_id': '7700000000000', 'region_iso_code': 'RU-MOW', 'region_with_type': 'г Москва', 'region_type': 'г', 'region_type_full': 'город', 'region': 'Москва', 'area_fias_id': None, 'area_kladr_id': None, 'area_with_type': None, 'area_type': None, 'area_type_full': None, 'area': None, 'city_fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'city_kladr_id': '7700000000000', 'city_with_type': 'г Москва', 'city_type': 'г', 'city_type_full': 'город', 'city': 'Москва', 'city_area': None, 'city_district_fias_id': None, 'city_district_kladr_id': None, 'city_district_with_type': None, 'city_district_type': None, 'city_district_type_full': None, 'city_district': None, 'settlement_fias_id': None, 'settlement_kladr_id': None, 'settlement_with_type': None, 'settlement_type': None, 'settlement_type_full': None, 'settlement': None, 'street_fias_id': None, 'street_kladr_id': None, 'street_with_type': None, 'street_type': None, 'street_type_full': None, 'street': None, 'stead_fias_id': None, 'stead_cadnum': None, 'stead_type': None, 'stead_type_full': None, 'stead': None, 'house_fias_id': None, 'house_kladr_id': None, 'house_cadnum': None, 'house_type': None, 'house_type_full': None, 'house': None, 'block_type': None, 'block_type_full': None, 'block': None, 'entrance': None, 'floor': None, 'flat_fias_id': None, 'flat_cadnum': None, 'flat_type': None, 'flat_type_full': None, 'flat': None, 'flat_area': None, 'square_meter_price': None, 'flat_price': None, 'room_fias_id': None, 'room_cadnum': None, 'room_type': None, 'room_type_full': None, 'room': None, 'postal_box': None, 'fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'fias_code': None, 'fias_level': '1', 'fias_actuality_state': '0', 'kladr_id': '7700000000000', 'geoname_id': '524901', 'capital_marker': '0', 'okato': '45000000000', 'oktmo': '45000000', 'tax_office': '7700', 'tax_office_legal': '7700', 'timezone': None, 'geo_lat': '55.75396', 'geo_lon': '37.620393', 'beltway_hit': None, 'beltway_distance': None, 'metro': None, 'divisions': None, 'qc_geo': '4', 'qc_complete': None, 'qc_house': None, 'history_values': None, 'unparsed_parts': None, 'source': None, 'qc': None}}
>>> type(result)
<class 'dict'>
>>>
>>> result['value']
'г Москва'
>>> result['data']
{'postal_code': '101000', 'country': 'Россия', 'country_iso_code': 'RU', 'federal_district': 'Центральный', 'region_fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'region_kladr_id': '7700000000000', 'region_iso_code': 'RU-MOW', 'region_with_type': 'г Москва', 'region_type': 'г', 'region_type_full': 'город', 'region': 'Москва', 'area_fias_id': None, 'area_kladr_id': None, 'area_with_type': None, 'area_type': None, 'area_type_full': None, 'area': None, 'city_fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'city_kladr_id': '7700000000000', 'city_with_type': 'г Москва', 'city_type': 'г', 'city_type_full': 'город', 'city': 'Москва', 'city_area': None, 'city_district_fias_id': None, 'city_district_kladr_id': None, 'city_district_with_type': None, 'city_district_type': None, 'city_district_type_full': None, 'city_district': None, 'settlement_fias_id': None, 'settlement_kladr_id': None, 'settlement_with_type': None, 'settlement_type': None, 'settlement_type_full': None, 'settlement': None, 'street_fias_id': None, 'street_kladr_id': None, 'street_with_type': None, 'street_type': None, 'street_type_full': None, 'street': None, 'stead_fias_id': None, 'stead_cadnum': None, 'stead_type': None, 'stead_type_full': None, 'stead': None, 'house_fias_id': None, 'house_kladr_id': None, 'house_cadnum': None, 'house_type': None, 'house_type_full': None, 'house': None, 'block_type': None, 'block_type_full': None, 'block': None, 'entrance': None, 'floor': None, 'flat_fias_id': None, 'flat_cadnum': None, 'flat_type': None, 'flat_type_full': None, 'flat': None, 'flat_area': None, 'square_meter_price': None, 'flat_price': None, 'room_fias_id': None, 'room_cadnum': None, 'room_type': None, 'room_type_full': None, 'room': None, 'postal_box': None, 'fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'fias_code': None, 'fias_level': '1', 'fias_actuality_state': '0', 'kladr_id': '7700000000000', 'geoname_id': '524901', 'capital_marker': '0', 'okato': '45000000000', 'oktmo': '45000000', 'tax_office': '7700', 'tax_office_legal': '7700', 'timezone': None, 'geo_lat': '55.75396', 'geo_lon': '37.620393', 'beltway_hit': None, 'beltway_distance': None, 'metro': None, 'divisions': None, 'qc_geo': '4', 'qc_complete': None, 'qc_house': None, 'history_values': None, 'unparsed_parts': None, 'source': None, 'qc': None}
>>>
>>> result['data']['country']
'Россия'
>>> result['data']['federal_district']
'Центральный'
>>>
Из этого делаю короткое приложение:
Код: Выделить всё
#!/usr/bin/python3
# https://github.com/hflabs/dadata-py
from dadata import Dadata
token = "ef835f86e5405beefe93c60ae0399ac21c89254e"
dadata = Dadata(token)
result = dadata.iplocate("213.159.214.240")
print(result)
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc$ ./iplocate.py
{'value': 'г Москва', 'unrestricted_value': '101000, г Москва', 'data': {'postal_code': '101000', 'country': 'Россия', 'country_iso_code': 'RU', 'federal_district': 'Центральный', 'region_fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'region_kladr_id': '7700000000000', 'region_iso_code': 'RU-MOW', 'region_with_type': 'г Москва', 'region_type': 'г', 'region_type_full': 'город', 'region': 'Москва', 'area_fias_id': None, 'area_kladr_id': None, 'area_with_type': None, 'area_type': None, 'area_type_full': None, 'area': None, 'city_fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'city_kladr_id': '7700000000000', 'city_with_type': 'г Москва', 'city_type': 'г', 'city_type_full': 'город', 'city': 'Москва', 'city_area': None, 'city_district_fias_id': None, 'city_district_kladr_id': None, 'city_district_with_type': None, 'city_district_type': None, 'city_district_type_full': None, 'city_district': None, 'settlement_fias_id': None, 'settlement_kladr_id': None, 'settlement_with_type': None, 'settlement_type': None, 'settlement_type_full': None, 'settlement': None, 'street_fias_id': None, 'street_kladr_id': None, 'street_with_type': None, 'street_type': None, 'street_type_full': None, 'street': None, 'stead_fias_id': None, 'stead_cadnum': None, 'stead_type': None, 'stead_type_full': None, 'stead': None, 'house_fias_id': None, 'house_kladr_id': None, 'house_cadnum': None, 'house_type': None, 'house_type_full': None, 'house': None, 'block_type': None, 'block_type_full': None, 'block': None, 'entrance': None, 'floor': None, 'flat_fias_id': None, 'flat_cadnum': None, 'flat_type': None, 'flat_type_full': None, 'flat': None, 'flat_area': None, 'square_meter_price': None, 'flat_price': None, 'room_fias_id': None, 'room_cadnum': None, 'room_type': None, 'room_type_full': None, 'room': None, 'postal_box': None, 'fias_id': '0c5b2444-70a0-4932-980c-b4dc0d3f02b5', 'fias_code': None, 'fias_level': '1', 'fias_actuality_state': '0', 'kladr_id': '7700000000000', 'geoname_id': '524901', 'capital_marker': '0', 'okato': '45000000000', 'oktmo': '45000000', 'tax_office': '7700', 'tax_office_legal': '7700', 'timezone': None, 'geo_lat': '55.75396', 'geo_lon': '37.620393', 'beltway_hit': None, 'beltway_distance': None, 'metro': None, 'divisions': None, 'qc_geo': '4', 'qc_complete': None, 'qc_house': None, 'history_values': None, 'unparsed_parts': None, 'source': None, 'qc': None}}
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc$ go build iplocate.go
iplocate.go:4:1: expected 'package', found 'import'
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc$ go build iplocate.go
iplocate.go:7:5: no required module provides package github.com/ekomobile/dadata/v2: go.mod file not found in current directory or any parent directory; see 'go help modules'
iplocate.go:8:5: no required module provides package github.com/ekomobile/dadata/v2/api/suggest: go.mod file not found in current directory or any parent directory; see 'go help modules'
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc/iplocate$ pwd
/home/olej/2023/own.WORK/geoloc/iplocate
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc/iplocate$ go mod init iplocate
go: creating new go.mod: module iplocate
go: to add module requirements and sums:
go mod tidy
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc/iplocate$ go mod tidy
go: finding module for package github.com/ekomobile/dadata/v2/api/suggest
go: finding module for package github.com/ekomobile/dadata/v2
go: downloading github.com/ekomobile/dadata v1.0.2
go: downloading github.com/ekomobile/dadata/v2 v2.7.0
go: found github.com/ekomobile/dadata/v2 in github.com/ekomobile/dadata/v2 v2.7.0
go: found github.com/ekomobile/dadata/v2/api/suggest in github.com/ekomobile/dadata/v2 v2.7.0
go: downloading github.com/stretchr/testify v1.7.1
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
go: downloading github.com/pmezard/go-difflib v1.0.0
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc/iplocate$ ls -l
итого 12
-rw-rw-r-- 1 olej olej 72 мар 17 21:15 go.mod
-rw-rw-r-- 1 olej olej 529 мар 17 21:15 go.sum
-rw-rw-r-- 1 olej olej 427 мар 17 20:36 iplocate.go
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc/iplocate$ go build iplocate.go
# command-line-arguments
./iplocate.go:8:5: "github.com/ekomobile/dadata/v2/api/suggest" imported and not used
./iplocate.go:14:5: result declared and not used
./iplocate.go:14:13: err declared and not used
Довёл их код до безошибочной сборки:
Код: Выделить всё
package main
// https://github.com/ekomobile/dadata
// Использует API-ключ из переменной окружения DADATA_API_KEY
import (
"context"
"fmt"
"github.com/ekomobile/dadata/v2"
)
func main() {
api := dadata.NewSuggestApi()
query := "46.226.227.20"
result, _ := api.GeoIP(context.Background(), query)
fmt.Printf("%v\n", *result)
}
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc/iplocate$ go build iplocate.go
olej@R420:~/2023/own.WORK/geoloc/iplocate$ ./iplocate
{<nil>}
Переделал так, чтобы ошибку было видно:
Код: Выделить всё
package main
// https://github.com/ekomobile/dadata
// Использует API-ключ из переменной окружения DADATA_API_KEY
import (
"context"
"fmt"
"github.com/ekomobile/dadata/v2"
)
func main() {
api := dadata.NewSuggestApi()
query := "46.226.227.20"
result, err := api.GeoIP(context.Background(), query)
if err != nil {
fmt.Printf("%v\n", err)
return
}
fmt.Printf("%v\n", result.Location.Value)
}
Код: Выделить всё
olej@R420:~/2023/own.WORK/geoloc/iplocate$ ./iplocate
doRequest: Request error 401 Unauthorized
И глядя на Python аналогиченое приложение:
Полагаю, что начальная инициализация в Go идёт без указания конкретного токена ... который, скорее всего, связан с моей индивидуальной регистрацией на их сайте: вот именно вот тот token.
Очень интересный обзор "о том как это делается":
27 фев 2020 в 12:02
Начало работ в этом направлении описано в статье, опубликованной в 2001 году. Основой измерительных технологий стал метод Constraint-based geolocation (CBG), заключающийся в измерении времени кругового обхода (RTT) при выполнении запроса echo-request ICMP от нескольких хостов с известной геопозицией (или landmarks в оригинале) к хосту с измеряемой геопозицией.
Код: Выделить всё
Эволюция CBG определила развитие и других методов геопозиционирования хостов по IP-адресу: Shortest ping, Topology-based geolocation (TBG), Octant, Street-level geolocation (SLG). В некоторых случаях удается достичь точности геопозиционирования хоста до здания, где он размещен (обычно ЦОД).
Вот прямо из shell:
Код: Выделить всё
olej@R420:~$ curl http://api.db-ip.com/v2/free/46.226.227.20
{
"ipAddress": "46.226.227.20",
"continentCode": "EU",
"continentName": "Europe",
"countryCode": "RU",
"countryName": "Russia",
"stateProv": "Krasnodar Krai",
"city": "Krasnodar"
}
olej@R420:~$curl http://api.db-ip.com/v2/free/213.159.214.240
{
"ipAddress": "213.159.214.240",
"continentCode": "EU",
"continentName": "Europe",
"countryCode": "RU",
"countryName": "Russia",
"stateProv": "Irkutsk Oblast",
"city": "Irkutsk"
}
Код: Выделить всё
olej@R420:~$ host linux-ru.ru
linux-ru.ru has address 90.156.230.27
linux-ru.ru mail is handled by 10 mx1.timeweb.ru.
linux-ru.ru mail is handled by 10 mx2.timeweb.ru.
olej@R420:~$ curl http://api.db-ip.com/v2/free/90.156.230.27
{
"ipAddress": "90.156.230.27",
"continentCode": "AS",
"continentName": "Asia",
"countryCode": "KZ",
"countryName": "Kazakhstan",
"stateProv": "Almaty",
"city": "Almaty"
}
Можно и так (на будущее):
Код: Выделить всё
olej@R420:~$curl http://api.db-ip.com/v2/free/46.226.227.20,213.159.214.240,90.156.230.27
{
"46.226.227.20": {
"continentCode": "EU",
"continentName": "Europe",
"countryCode": "RU",
"countryName": "Russia",
"stateProv": "Krasnodar Krai",
"city": "Krasnodar"
},
"213.159.214.240": {
"continentCode": "EU",
"continentName": "Europe",
"countryCode": "RU",
"countryName": "Russia",
"stateProv": "Irkutsk Oblast",
"city": "Irkutsk"
},
"90.156.230.27": {
"continentCode": "AS",
"continentName": "Asia",
"countryCode": "KZ",
"countryName": "Kazakhstan",
"stateProv": "Almaty",
"city": "Almaty"
}
}
Код: Выделить всё
olej@R420:~$ curl http://api.db-ip.com/v2/free/103.152.248.133,51.91.18.222
{
"103.152.248.133": {
"continentCode": "OC",
"continentName": "Oceania",
"countryCode": "AU",
"countryName": "Australia",
"stateProvCode": "VIC",
"stateProv": "Victoria",
"city": "Melbourne"
},
"51.91.18.222": {
"continentCode": "EU",
"continentName": "Europe",
"countryCode": "FR",
"countryName": "France",
"stateProv": "Hauts-de-France",
"city": "Roubaix"
}
}
Сейчас этот форум просматривают: нет зарегистрированных пользователей и 5 гостей