How to store and search for an IP Address

前端 未结 7 1296
北海茫月
北海茫月 2021-01-20 02:56

I have the 4 sources of IP addresses , I want to store them in SQL Server and allow the ranges, that can be categorised by the originating country code, to be maked in an E

7条回答
  •  孤街浪徒
    2021-01-20 03:13

    I've done a filter by country exactly like you describe.

    However, after experimenting a while, I found out that it can't be done in a performant way with SQL. That's why IP databases like this one (the one I'm using) offer a binary database, which is much faster because it's optimized for this kind of data.

    They even say explicitly:

    Note that queries made against the CSV data imported into a SQL database can take up to a few seconds. If performance is an issue, the binary format is much faster, and can handle thousands of lookups per second.

    Plus, they even give you the code to query this database.

    I'm using this in a production website with medium traffic, filtering every request, with no performance problems.

提交回复
热议问题