之前想过的一个问题“如何保持系统上的某些数据文件为最新版本?”,当时开了个头之后就没有继续下去,今天又回想起来了,然后又经过这么多天的一些“暗时间”的思考,大概的思路就有了:
之前在为VPS解析IP对应的地理位置时,使用了纯真数据库,但那都已经是几个月之前的问题了,虽然一直以来效果什么的也还行,没什么大问题,但是有时候在查看Nginx的日志文件时觉得IP定位什么的还可以再准一些(尤其是那些扫描什么的最可恶了),所以需要有个能够实时更新服务器上的qqwry.dat文件的方法,想了想,如果是在全天运行的服务器上,可以通过每隔一段时间(cron)去访问/读取(curl/wget)该文件的大小(Content-Length),若大小发生变化(if判断),则下载该文件并替换本地文件,这样的话就可以保持该文件处于最新状态了。
与此对应的还有Exploit-db的数据库(经常更新){ http://www.exploit-db.com/archive.tar.bz2 },可以参考之前写过的一篇文章:关于Exploit-DB漏洞库的使用。
下面就以QQwry.dat这个纯真数据库的文件更新为例说一下:
1.获取qqwry.dat.zip文件的大小(返回值中的 Content-Length):
# curl -I http://www.newxing.com/D6C47427E608/qqwry.dat
通过命令组合获取本地qqwry.dat.zip文件的大小,然后和网站上提供的文件的大小进行比较,从而判断是否需要下载并更新。
oldSize=`ls -l qqwry.dat.zip | awk '{print $5}'` newSize=`curl -s -I http://www.newxing.com/D6C47427E608/qqwry.dat | grep Content-Length` if [$oldSize != $newSize];then #这里其实既可以作为字符串比较也可以作为数字进行比较{只要两者不同即可} wget -O qqwry.dat.zip http://www.newxing.com/D6C47427E608/qqwry.dat unzip -o qqwry.dat.zip fi
####
整数变量表达式 if [ int1 -eq int2 ] #如果int1等于int2 if [ int1 -ne int2 ] #如果不等于 字符串变量表达式 if [ $a = $b ] #如果string1等于string2{字符串允许使用赋值号做等号} if [ $a == $b ] #如果string1等于string2{也允许使用双等号} if [ $string1 != $string2 ] #如果string1不等于string2
####
2.下载qqwry.dat文件:
# wget http://www.newxing.com/D6C47427E608/qqwry.dat
要注意的一点就是直接wget的话下载的文件名就是qqwry.dat,但你用file命令进行查看的话就会知道该文件其实是个zip格式的压缩文件:
# file qqwry.dat
qqwry.dat: Zip archive data, at least v2.0 to extract
3.修改后缀(其实也可以不用改,但为了直观显示文件格式,还是建议修改):
# mv qqwry.dat qqwry.dat.zip
4.unzip解压:
# unzip qqwry.dat.zip #默认情况下unzip会询问是否替换已存在的文件,所以可以带上”-o”选项直接overwrite而不给提示以免脚本执行中断
也可以在wget的时候就改名然后直接unzip即可:
1.获取文件大小,判断是否需要进行更新;
2.下载的同时设置文件名:# wget -O qqwry.dat.zip http://www.newxing.com/D6C47427E608/qqwry.dat
3.解压:# unzip qqwry.dat.zip #{如果当前文件夹中已存在qqwry.dat则需要添加-o选项强制覆盖并不给出提示}
PS:才发现EditPlus原来有个hex viewer的功能,还是很不错的{要是这样的话就可以不用受到WinHex的文件大小限制了}
wget的-o和-O选项的辨别:
即,-o是指定log文件存放的名称的;-O是指定下载的文件内容要存放的文件名的。
curl的选项复习:
-I, –head Show document info only #仅显示头部信息
-s, –silent Silent mode. Don’t output anything #静默模式
unzip命令的样例:
unzip data1.zip -x joe => 解压data1.zip压缩包中除了joe之外的所有文件 unzip -p foo.zip | more =>解压foo.zip压缩包中的内容并传给管道 unzip -fo foo.zip ReadMe => 如果压缩包中的ReadMe文件比外部的要新则进行提取并替换
#update @ 20160808
最近发现有些IP的位置解析不太准,想了想应该是纯真IP库的数据太老了,所以决定更新一下纯真IP库,发现下载地址也变了,所以上面的内容已经不适用了,不过思路还是一样的,下面更新一下现在可用的下载和更新方式:
file_name="QQwry.dat.$(date +%F).rar" wget -O "$file_name" "http://www.newxing.com/Code/download.asp?softid=608&downid=8&id=611" if [ $? -eq 0 ]; then calc_md5=$(md5sum "$file_name" | awk '{print $1}') file_md5=$(curl -s "http://www.newxing.com/Code/tool/QQwry.dat_608.html" | grep -oE 'var md5="\w+"' | awk -F\" '{print $2}') if [ "$calc_md5" == "$file_md5" ]; then echo "OK." fi fi #解压rar文件至当前目录 unrar e -f QQwry.dat.$(date +%F).rar #尝试更新 unrar e -y QQwry.dat.$(date +%F).rar #强制更新
=END=
《 “如何实时更新一些数据文件?” 》 有 6 条评论
使用Python写一个转存纯真IP数据库的脚本
http://www.92ez.com/?action=show&id=23442
https://github.com/kbdancer/myTools/tree/master/czip2mysql
send/post xml file using curl command line
https://stackoverflow.com/questions/3007253/send-post-xml-file-using-curl-command-line
`
curl -v -X POST “http://localhost/api/addBlack” \
-F “keyName=rivalIP” \
-F “desc=竞对IP” \
-F “[email protected]”
`
Using curl to upload POST data with files
https://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-files
https://superuser.com/questions/1054742/how-to-post-file-contents-using-curl
[水木社区 >> 社会信息 >> 求职招聘 >> 社会招聘 >> 文章列表]搜索关键字【字节】或其它关键字
https://www.newsmth.net/nForum/#!s/article?t1=%25E5%25AD%2597%25E8%258A%2582&au=&b=Career_Upgrade
`
发信人: YiPianDanNi (一片丹妮), 信区: Career_Upgrade
标 题: 【内推】【社招】字节跳动后端研发岗招聘
发信站: 水木社区 (Sat Mar 20 17:34:15 2021), 站内
…
※ 来源:·水木社区 … ·[FROM: 49.7.44.*]
发信人: grapeisme (masakaaa), 信区: Career_Upgrade
标 题: 【字节跳动-大力教育】急招高级数据分析师
发信站: 水木社区 (Sun Apr 25 11:39:33 2021), 站内
…
※ 来源:·水木社区 … ·[FROM: 123.58.117.*]
发信人: joyyan (joyyan), 信区: Career_Upgrade
标 题: 【字节跳动】【内推社招】【服务端测试开发工程师】
发信站: 水木社区 (Tue Apr 20 11:40:26 2021), 站内
…
※ 来源:·水木社区 … ·[FROM: 123.58.117.*]
`
$ whois 103.102.203.201
% IANA WHOIS server
% for more information on IANA, visit http://www.iana.org
% This query returned 1 object
refer: whois.apnic.net
inetnum: 103.0.0.0 – 103.255.255.255
organisation: APNIC
status: ALLOCATED
whois: whois.apnic.net
changed: 2011-02
source: IANA
# whois.apnic.net
% [whois.apnic.net]
% Whois data copyright terms http://www.apnic.net/db/dbcopyright.html
% Information related to ‘103.102.200.0 – 103.102.203.255’
% Abuse contact for ‘103.102.200.0 – 103.102.203.255’ is ‘[email protected]’
inetnum: 103.102.200.0 – 103.102.203.255
netname: KUAISHOU-NET
descr: Reach Best Co.,Ltd.
country: CN
admin-c: GZ1772-AP
tech-c: GZ1772-AP
abuse-c: AC1601-AP
status: ALLOCATED PORTABLE
mnt-by: MAINT-CNNIC-AP
mnt-lower: MAINT-CNNIC-AP
mnt-routes: MAINT-CNNIC-AP
mnt-irt: IRT-CNNIC-CN
last-modified: 2025-03-03T07:05:18Z
source: APNIC
irt: IRT-CNNIC-CN
address: Beijing, China
e-mail: [email protected]
abuse-mailbox: [email protected]
admin-c: IP50-AP
tech-c: IP50-AP
auth: # Filtered
remarks: Please note that CNNIC is not an ISP and is not
remarks: empowered to investigate complaints of network abuse.
remarks: Please contact the tech-c or admin-c of the network.
mnt-by: MAINT-CNNIC-AP
last-modified: 2021-06-16T01:39:57Z
source: APNIC
role: ABUSE CNNICCN
country: ZZ
address: Beijing, China
phone: +000000000
e-mail: [email protected]
admin-c: IP50-AP
tech-c: IP50-AP
nic-hdl: AC1601-AP
remarks: Generated from irt object IRT-CNNIC-CN
abuse-mailbox: [email protected]
mnt-by: APNIC-ABUSE
last-modified: 2024-07-30T11:55:46Z
source: APNIC
person: Gu Zengyun
address: No. 29, Yuan Center, Xierqi Middle Road, Haidian District, Beijing, China
country: CN
phone: +86-13910557413
e-mail: [email protected]
nic-hdl: GZ1772-AP
mnt-by: MAINT-CNNIC-AP
last-modified: 2025-03-03T07:02:32Z
source: APNIC
% This query was served by the APNIC Whois Service version 1.88.34 (WHOIS-AU4)
$
$ whois 103.7.29.6
% IANA WHOIS server
% for more information on IANA, visit http://www.iana.org
% This query returned 1 object
refer: whois.apnic.net
inetnum: 103.0.0.0 – 103.255.255.255
organisation: APNIC
status: ALLOCATED
whois: whois.apnic.net
changed: 2011-02
source: IANA
# whois.apnic.net
% [whois.apnic.net]
% Whois data copyright terms http://www.apnic.net/db/dbcopyright.html
% Information related to ‘103.7.28.0 – 103.7.31.255’
% Abuse contact for ‘103.7.28.0 – 103.7.31.255’ is ‘[email protected]’
114.251.196.106 -byted
https://www.ipip.net/ipquery.html