| 1 | package Mojo::Webqq::Plugin::IPwhere; | ||
| 2 | our $PRIORITY = 1; | ||
| 3 | use IP::IPwhere; | ||
| 4 | #use IP::QQWry; #使用纯真库注释掉本行 | ||
| 5 | use Encode; | ||
| 6 | |||
| 7 | =pod | ||
| 8 | |||
| 9 | 插件使用方法给加载插件的账号发 IPwhere IP | ||
| 10 | 或者QQ群里发IPwhere IP. | ||
| 11 | |||
| 12 | 例子: | ||
| 13 | |||
| 14 | IPwhere 166.111.166.100 | ||
| 15 | |||
| 16 | result : | ||
| 17 | |||
| 18 | taobao 166.111.166.100:中国,北京市,北京市,教育网 | ||
| 19 | sina 166.111.166.100:中国,北京,北京, | ||
| 20 | baidu 166.111.166.100:北京市海淀区 教育网 | ||
| 21 | pconline 166.111.166.100:北京市,北京市,,北京市 教育网 | ||
| 22 | qqwry 166.111.166.100:清华大学学生宿舍14号楼 | ||
| 23 | |||
| 24 | |||
| 25 | 本插件需要安装模块IP::IPwhere,如果你需要纯真的信息 | ||
| 26 | 还要安装IP::QQWry,以及下载纯真的数据库QQWry.Dat | ||
| 27 | 下载地址: | ||
| 28 | |||
| 29 | https://github.com/bollwarm/ipwhere/blob/master/QQWry.Dat | ||
| 30 | |||
| 31 | oschina同步更新,如果github太慢通过osc下载 | ||
| 32 | |||
| 33 | https://git.oschina.net/ijz/ipwhere/raw/master/QQWry.Dat | ||
| 34 | 安装库可以简单通过cpanm IP::IPwhere IP::QQWry | ||
| 35 | |||
| 36 | 并把下面部分注释掉。 | ||
| 37 | |||
| 38 | my $qqwry = IP::QQWry->new('QQWry.Dat'); | ||
| 39 | |||
| 40 | sub gquery { | ||
| 41 | |||
| 42 | my ($ip)=shift; | ||
| 43 | my ($base,$info) = $qqwry->query($ip); | ||
| 44 | my $result; | ||
| 45 | $result="qqwry $ip:"; | ||
| 46 | $result.=decode('gbk',$base); | ||
| 47 | $result.=decode('gbk',$info)."\n"; | ||
| 48 | return $result; | ||
| 49 | |||
| 50 | } | ||
| 51 | =cut | ||
| 52 | |||
| 53 | my $re=qr([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]); | ||
| 54 | my $ipre=qr/($re\.){3}$re$/; | ||
| 55 | |||
| 56 | sub call { | ||
| 57 | my $client = shift; | ||
| 58 | $client->on(receive_message=>sub{ | ||
| 59 | my($client,$msg)=@_; | ||
| 60 | return if not $msg->allow_plugin; | ||
| 61 | return if $msg->content !~ /^(ipwhere|IPwhere)\s*($ipre)/; | ||
| 62 | my $arg= $1 if $msg->content=~ /^(ipwhere|IPwhere)\s*($ipre)/; | ||
| 63 | $reply= Encode::encode("utf8",squery($arg)); | ||
| 64 | # $reply.=Encode::encode("utf8",gquery($arg)); # 如果需要解析纯真数据库,吧本行注释去掉 | ||
| 65 | $msg->reply($reply,sub{$_[1]->from("bot")}) if $reply; | ||
| 66 | }); | ||
| 67 | } | ||
| 68 | 1; |