Home Database Mysql Tutorial 淘宝IP地址库设计

淘宝IP地址库设计

Jun 07, 2016 pm 03:59 PM
no for address Taobao design choose project

当初选择做这么一个项目,不是为了拷贝一份库自己做服务,也不是为了其他目的,只是单纯的熟悉关于http和mysql方面的知识。 下面言归正传。 1、淘宝IP地址库简介 此地址库可以根据用户提供的IP地址,快速查询出该IP地址所在的地理信息和地理相关的信息,包括

当初选择做这么一个项目,不是为了拷贝一份库自己做服务,也不是为了其他目的,只是单纯的熟悉关于http和mysql方面的知识。
下面言归正传。

1、淘宝IP地址库简介
此地址库可以根据用户提供的IP地址,快速查询出该IP地址所在的地理信息和地理相关的信息,包括国家、省、市和运营商。
用户也可以主动提交信息来纠错。
主要优势表现为:
(1)地域
覆盖度:94.54% 精确到市级
准确度:96.5% 精确到市级
(2)运营商
覆盖度:93.8%
准确度:暂无统计数据
(3)查询速度
10qps
注:阿里同机房内网,实测速度为4qps左右。
(4)接口
符合REST规范,方便扩展;
使用JSON作为数据格式,方便使用;

2、基础数据
下面介绍一下,需要使用到的一些基础数据项,以及来源。
首先,我们来分析一下淘宝IP地址库的返回数据,
{
"code" : 0, // 请求成功/失败
"data" : {
"country" : "\u4e2d\u56fd", // 国家
"country_id" : "CN", // 国家代码
"area" : "\u534e\u5317", // 地区
"area_id" : "100000", // 地区代码
"region" : "\u5317\u4eac\u5e02", // 省(自治区、直辖市、特别行政区)
"region_id" : "110000", // 省代码
"city" : "\u5317\u4eac\u5e02", // 市(地区、自治州、盟及国家直辖市所属市辖区和县)
"city_id" : "110000", // 市代码
"county" : "", // 县(市辖区、县级市、旗)
"county_id" : "-1", // 县代码
"isp" : "\u4e2d\u56fd\u79d1\u6280\u7f51", // 运营商
"isp_id" : "1000114", // 运营商代码
"ip" : "210.75.225.254" // ipv4/ipv6
}
}
其中:
国家与国家代码,由联合国统计局统一制定。详见:http://zh.wikipedia.org/wiki/ISO_3166-1
地区、省、市、县以及相应的代码,由中华人民共和国国家统计局统一制定,详见:http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201401/t20140116_501070.html
运营商与运营商代码,由国际电联电信标准化部门统一制定,不过已经很久没有维护,不可用。到目前为止,本人也没有找到一份完整的编码表,希望知晓者告知。暂且就以淘宝IP地址库中编码为准。
国家IP地址段,由互联网IP地址分配中心统一管理,在此附上中文版的地址段信息,详见程默的博客,在此表示感谢:http://ipblock.chacuo.net/

3、数据库设计
(1)数据项及命名
国家 country
地区 region
省(自治区、直辖市、特别行政区) province
市(地区、自治州、盟及国家直辖市所属市辖区和县) city
县(市辖区、县级市、旗) county
镇(乡、城镇) town
村(村庄) village
运营商 isp
IP ip

(2)IP表
国家代码 2个字节 CHAR(2)
县代码 6位整形 UINT(20)
村代码 12位整形 UINT(40)
运营商代码 7位整形 UINT(24)
IP地址 4个字节 UINT(32)

(3)国家表
二位字母 2个字节 CHAR(2)
三位字母 3个字节 CHAR(3)
三位数字 3位整形 UINT(10)
ISO英文用名 48个字节 CHAR(48)
中文用名 48个字节 CHAR(48)

(4)地区表
代码 1位整形 UINT(4)
名称 4个字节 CHAR(4)

(5)县(市辖区、县级市、旗)表
代码 6位整形 UINT(20)
名称 48个字节 CHAR(48)

(6)村(村庄)表
代码 12位整形 UINT(40)
名称 48个字节 CHAR(48)

(7)运营商表
代码 7位整形 UINT(24)
名称 48个字节 CHAR(48)

4、数据采集
IP运营商信息来源于各个运营商,IP所属地域信息来源于CNNIC,不过这些信息不太容易拿到完整的。
所以,此处就以淘宝IP地址库为来源。

5、实现方案
使用 nodejs + python 实现,nodejs主要实现网络交互集中的部分,python主要实现网页抓取。数据库使用常见的 mysql。
(1)国家代码抓取
使用 python 实现从 http://zh.wikipedia.org/wiki/ISO_3166-1 地址抓取代码信息,并保存文本country.txt。当然,也可以直接手动拷贝粘贴到文本中。
使用 nodejs 按行读取上一步抓取到的文本,做处理,使用 node-mysql 写入数据库。

(2)县代码抓取
使用 python 实现从 http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201401/t20140116_501070.html 地址抓取代码信息,并保存文本cncounty.txt。当然,也可以直接手动拷贝粘贴到文本中。
使用 nodejs 按行读取上一步抓取到的文本,做处理,使用 node-mysql 写入数据库。

(3)国内IP段抓取
使用 python 实现从 http://ipblock.chacuo.net/ 地址抓取IP段信息,并保存文本cnip.txt。当然,也可以直接手动拷贝粘贴到文本中。

(4)IP地址信息查询
使用 nodejs 读取 cnip.txt 文本,每次解析10000个IP,使用 http 模块从淘宝IP地址库查询结果,并使用 node-mysql 写入数据库。
由于在 nodejs 中 http 处理和 mysql 处理都是异步操作,所以,增加一个缓冲区,保存http请求结果。笔者使用了经典的生产者消费者模型来处理这个问题。

6、结果
为了保证请求的稳定,使用阿里云服务器运行此系统。
实际运行时,每秒可以稳定的请求到5个IP信息,中国目前(截止2014年1月)拥有3.3亿IP,完成全部请求大约需要2.98天。

完成全部存储,数据库大小为22.3GB。

转载请注明来自隐居士(石硕)的CSDN博客:blog.csdn.net/shishuo365 如有疑问请发邮件shishuo365#126.com(将#更换为@)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to get Taobao free red envelope 2024 How to get Taobao free red envelope 2024 May 09, 2024 pm 03:22 PM

The 2024 Taobao free order event will be held three times a day. Everyone needs to place an order and pay for the corresponding amount of goods at the corresponding time. The free order amount will be distributed in the form of red envelopes of equal amounts. Next, we will bring you how to receive the Taobao free order red envelope in 2024: grab it For users who are free of charge, the red envelope qualification will be issued to the card and coupon package, which is in a state of activation; the web version of Taobao currently does not have the card and coupon package, and only displays the winning records of the free order event; the card and coupon package is in [Taobao APP-My Taobao] -My Rights-Red Envelope]. How to get red envelopes for free orders on Taobao 20241. For users who grab free orders, the red envelope qualifications will be distributed to the card and coupon packages, which are in a state of waiting for activation; 2. The web version of Taobao currently does not have card and coupon packages, and only displays the winning records of the free order activities. ;3. The card coupon package is in [Taobao APP-My Taobao-My Rights-Red Envelope]

Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Apr 09, 2024 pm 03:20 PM

Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

How to turn off red envelope reminder on Taobao How to turn off red envelope reminder on Taobao Apr 01, 2024 pm 06:25 PM

Taobao is a commonly used online shopping software for many friends. You usually place orders and purchase many things from Taobao. It provides users with a red envelope reminder function. Some friends want to turn it off, so hurry up and check out the PHP Chinese website. Take a look. List of steps to turn off red envelope reminders on Taobao 1. Open the personal center of Taobao APP and select the [Settings] button to enter the page. 2. Find the [Message Notification] option. Here you can select the message push switch. Find the red envelope message and turn off the switch. 3. Or you can turn off the notification permission of Taobao APP through the settings page of your mobile phone, so that all messages from Taobao will not enter the push and can only be seen after turning it on. 4. Users can set what types of messages they want to receive, which makes it easier to use.

How to use 'Taobao' 510 free red envelope How to use 'Taobao' 510 free red envelope May 08, 2024 pm 10:00 PM

How to use Taobao 510 free red envelope? Taobao recently launched a free order event to celebrate its 510th anniversary. This event allows you to get free order red envelopes, and there are many benefits. I believe many friends want to participate in this event. Some friends have already received free order red envelopes, but they are not. If you know the specific usage, let’s take a look at the relevant introduction today. Instructions for using Taobao’s 510th Anniversary Free Order Red Packet: The free order red pack can be used after all orders placed for guessing questions have been confirmed and received. 1. Users can issue and recover free red envelopes through the web version of Taobao. Currently, there is no card and coupon package, but it can be viewed at [Taobao APP-My Taobao-My Rights-Red Envelopes]. For users who grab the free order, the red envelope qualification will be distributed to the card and coupon package, which is in a state of activation; the card and coupon package is in progress for winning prizes.

ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps Apr 26, 2024 pm 03:46 PM

According to news on April 26, ZTE’s 5G portable Wi-Fi U50S is now officially on sale, starting at 899 yuan. In terms of appearance design, ZTE U50S Portable Wi-Fi is simple and stylish, easy to hold and pack. Its size is 159/73/18mm and is easy to carry, allowing you to enjoy 5G high-speed network anytime and anywhere, achieving an unimpeded mobile office and entertainment experience. ZTE 5G portable Wi-Fi U50S supports the advanced Wi-Fi 6 protocol with a peak rate of up to 1800Mbps. It relies on the Snapdragon X55 high-performance 5G platform to provide users with an extremely fast network experience. Not only does it support the 5G dual-mode SA+NSA network environment and Sub-6GHz frequency band, the measured network speed can even reach an astonishing 500Mbps, which is easily satisfactory.

Will 'Taobao' free red envelope refunds be returned? Will 'Taobao' free red envelope refunds be returned? May 08, 2024 am 08:16 AM

When shopping on Taobao, we often use free red envelopes to enjoy discounts. But if we need a refund, will these free red envelopes be returned? Let's take a look at the answer to this question. Will Taobao's free red envelopes be refunded? Depending on the situation, when you receive a red envelope, the red envelope is in a pending activation state. Before redeeming the product, the to-be-activated red envelope is not activated and cannot be used temporarily. You will wait until receipt of the purchased goods is confirmed. , the red envelope that needs to be activated can be used. If there is a problem with the product after using the free red envelope and it needs to be returned, the return of the red envelope needs to be judged according to the actual situation: 1. Refund Rules 11. If a refund occurs after the red envelope is used, the red envelope will be returned in proportion. 2. If the red envelope is not overdue, the period of use of the returned red envelope is the original period of use. If it is overdue, it will be issued within 7 days.

Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Apr 17, 2024 pm 06:50 PM

According to news on April 17, HMD teamed up with the well-known beer brand Heineken and the creative company Bodega to launch a unique flip phone - The Boring Phone. This phone is not only full of innovation in design, but also returns to nature in terms of functionality, aiming to lead people back to real interpersonal interactions and enjoy the pure time of drinking with friends. Boring mobile phone adopts a unique transparent flip design, showing a simple yet elegant aesthetic. It is equipped with a 2.8-inch QVGA display inside and a 1.77-inch display outside, providing users with a basic visual interaction experience. In terms of photography, although it is only equipped with a 30-megapixel camera, it is enough to handle simple daily tasks.

Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Jul 18, 2024 am 09:27 AM

According to news on July 12, the Honor Magic V3 series was officially released today, equipped with the new Honor Vision Soothing Oasis eye protection screen. While the screen itself has high specifications and high quality, it also pioneered the introduction of AI active eye protection technology. It is reported that the traditional way to alleviate myopia is "myopia glasses". The power of myopia glasses is evenly distributed to ensure that the central area of ​​​​sight is imaged on the retina, but the peripheral area is imaged behind the retina. The retina senses that the image is behind, promoting the eye axis direction. grow later, thereby deepening the degree. At present, one of the main ways to alleviate the development of myopia is the "defocus lens". The central area has a normal power, and the peripheral area is adjusted through optical design partitions, so that the image in the peripheral area falls in front of the retina.

See all articles