pythondownloadipip2location

How to get IP addresses from ip2location database?


I have downloaded IP2Proxy™ LITE database in CSV format, below is the data in it:

enter image description here

How can I read the IP addresses using Python or PowerShell, as it seems in plain number, rather than a standard dotted quad. Also, please explain what does the first two columns represent.


Solution

  • Here's how you can convert those values into a string representation of an IPv4 address:

    def convert(ip):
            def _genip(n):
                for shift in range(24, -8, -8):
                    yield f'{(n >> shift) & 0xff:03d}'
            return '.'.join(_genip(int(ip)))
    print(convert('34676992'))
    

    Output:

    002.017.033.000