有效的ip->位置查询 [英] Effective ip->location query

查看:153
本文介绍了有效的ip->位置查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表格:一个是来自ipinfodb.com的ip_group_city,包含用于确定IP位置的ip_start号码,另一个是包含列ip的网站访问者信息的访问。



我需要从访问表中检查每个IP的region_code,从而选择前10个region_code(来自ip_group_city)。



现在,我将所有来自访问的IP加载到数组中,并使用该IP信息通过以下方式查询ip_group_city:

  SELECT region_code 
FROM ip_group_city
WHERE ip_start< = INET_ATON(IP_FROM_ARR)
ORDER BY ip_start DESC LIMIT 1

我无法创建某种嵌套查询来为我完成这项工作,因为现在情况有点慢:) - 笔记本电脑上的xampp需要长达30秒(AMD炫龙x2 2GHz,运行windows 7终极版64位版本)



以下是IP地址表(访问次数)表

  CREATE TABLE IF NOT EXISTS`visits`(
` id` int(10)unsigned NOT NULL AUTO_INCREMENT,
`clientid` mediumint(8)unsigned NOT NULL,
`ip` varchar(15)NOT NULL,
`url` varchar(512)NOT NULL,
`client_version` varchar(64)NOT NULL,
PRIMARY KEY(`id`)
)ENGINE = MyISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT = 49272;

谢谢

解决方案 div>

既然你说过其他解决方案是受欢迎的......



您可能想查看 MaxMind 。他们通过IP获得了良好的国家和城市查询。您可以安装一个Apache或PHP插件以使其更快 - 甚至无需亲自处理数据库。


I have two tables: one is ip_group_city from ipinfodb.com containing ip_start numbers for determining location of IPs, and other is "visits" with information about web site visitor containing column 'ip'.

I need to select top 10 region_code (from ip_group_city) by checking region_code for each IP from "visits" table.

Right now I'm loading all IPs from "visits" into an array and using that IP info to query the ip_group_city by:

SELECT region_code
FROM ip_group_city
WHERE ip_start <= INET_ATON(IP_FROM_ARR)
ORDER BY ip_start DESC LIMIT 1

I'm unable to create some sort of nested query to do the job for me, because right now things are a bit slow :) - it takes up to 30s on my laptop xampp (AMD Turion x2 2GHz, running windows 7 ultimate 64bit version)

Here's the table with IP addresses (visits)

CREATE TABLE IF NOT EXISTS `visits` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`clientid` mediumint(8) unsigned NOT NULL,
`ip` varchar(15) NOT NULL,
`url` varchar(512) NOT NULL,
`client_version` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=49272 ;

Thanks

解决方案

Since you said other solutions are welcomed...

You might want to check out MaxMind. They have good country and city lookups by IP. You can install an Apache or PHP plugin to make it fast - don't even have to handle the database yourself.

这篇关于有效的ip-&gt;位置查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆