How to determine if an IP address belongs to a country

前端 未结 11 1186
情歌与酒
情歌与酒 2020-12-07 17:55

How would i determine the country that a spcific IP address is originating from using c#. I need to use this to check if connections originate from a specific country.

11条回答
  •  余生分开走
    2020-12-07 18:48

    ip2cc - Lookup country and Russia region by IP address Python module with script to create database from up-to-date official data.

    This Python utility loads (as frequently as you like) up-to-date information from Regional Internet Registry sites (arin, ripencc, apnic, lacnic, afrinic), as shown in the source:

    url_template = 'ftp://ftp.ripe.net/pub/stats/%s/delegated-%s-latest'
    sources = {}
    for name in ('arin', 'ripencc', 'apnic', 'lacnic', 'afrinic'):
        sources[name] = url_template % (name, name)
    

    Once the data is loaded, queries can be answered offline and very quickly. Can be easily modified to directly answer the original question, or used from the command line to return the country an IP address belongs to.

提交回复
热议问题