BOIP.NET 更新了小bug,数据库改为自动更新 【附上代码】
1. 把IPv6替换了使用新的
2. 将IPv6地址的ASN 改为 whois方式获取
1 2 3 4 5 6 |
$query = shell_exec('whois -h whois.cymru.com " -v -w -f -u -q -d '.$IP.'"'); $temp = explode('|',$query); $data['ASN'] = trimall($temp['0']); $data['RIR'] = trimall($temp['2']); $data['RIR_DATE'] = trimall($temp['3']); $data['ORG'] = trim($temp['4']); |
3. 修复了数据库延时的问题 改为每周自动更新
更新用到的代码 直接shell运行了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
/* 定时任务 1 4 * * 7 cd /home/admin/domains/boip.net/public_html/app/;php -q update.php 每周末的早上4点01分开始更新 */ /* Update IP2LOC 这个注意下 直接使用WGET进行POST用户下载GEO DB的BIN文件 */ shell_exec('rm -rf IP2LOCATION-LITE-DB11.BIN.ZIP'); shell_exec('rm -rf IP2LOCATION-LITE-DB11.IPV6.BIN.ZIP'); shell_exec('wget -O IP2LOCATION-LITE-DB11.BIN.ZIP --post-data="[email protected]&password=你的密码I&rememberMe=on" \ "http://lite.ip2location.com/login?return=http%3A%2F%2Flite.ip2location.com%2Fdownload%3Fid%3D10"'); shell_exec('wget -O IP2LOCATION-LITE-DB11.IPV6.BIN.ZIP --post-data="[email protected]&password=你的密码&rememberMe=on" \ "http://lite.ip2location.com/login?return=http%3A%2F%2Flite.ip2location.com%2Fdownload%3Fid%3D20"'); shell_exec('unzip -o IP2LOCATION-LITE-DB11.BIN.ZIP'); shell_exec('unzip -o IP2LOCATION-LITE-DB11.IPV6.BIN.ZIP'); shell_exec('mv -f IP2LOCATION-LITE-DB11.BIN GeoDB/IP2LOCATION-LITE-DB11.BIN'); shell_exec('mv -f IP2LOCATION-LITE-DB11.IPV6.BIN GeoDB/IP2LOCATION-LITE-DB11.IPV6.BIN'); /* Update qqway.dat */ $copywrite = file_get_contents("http://update.cz88.net/ip/copywrite.rar"); $qqwry = file_get_contents("http://update.cz88.net/ip/qqwry.rar"); $key = unpack("V6", $copywrite)['6']; for($i=0; $i<0x200; $i++) { $key *= 0x805; $key ++; $key = $key & 0xFF; $qqwry[$i] = chr( ord($qqwry[$i]) ^ $key ); } $qqwry = gzuncompress($qqwry); $fp = fopen("GeoDB/qqwry.dat", "wb"); if($fp) { fwrite($fp, $qqwry); fclose($fp); } /* Update Maxmind Data */ //shell_exec('ls -l'); shell_exec('wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz'); shell_exec('wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz'); shell_exec('gunzip GeoLite2-Country.mmdb.gz'); shell_exec('gunzip GeoLite2-City.mmdb.gz'); unlink('GeoDB/GeoLite2-Country.mmdb'); unlink('GeoDB/GeoLite2-City.mmdb'); shell_exec('mv Geo*.mmdb GeoDB/'); shell_exec('chown admin:admin -R GeoDB'); |