From e3f12ec9f5d6b978eaabd576901384b6ad53e8c2 Mon Sep 17 00:00:00 2001 From: DD6181S03 Date: Mon, 2 Mar 2020 21:15:18 +0800 Subject: [PATCH] add ip and dns lookup --- worker/ip.py | 32 ++++++++++++++++++++++++++++++++ worker/ns.py | 9 +++++++++ worker/yiyan.py | 11 +++++------ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 worker/ip.py create mode 100644 worker/ns.py diff --git a/worker/ip.py b/worker/ip.py new file mode 100644 index 0000000..67cdc29 --- /dev/null +++ b/worker/ip.py @@ -0,0 +1,32 @@ +from zzcore import StdAns +import requests + +class Ans(StdAns): + def GETMSG(self): + try: + ip = self.parms[0] + except: + ip = '' + url = 'https://api.ip.sb/geoip/' + if ip == '' or ip == 'help': + ret = '您可以使用 "/ip ip地址" 进行查找' + else: + res = requests.get(url + ip) + rsc = res.status_code + rem = res.json() + if rsc == 400: + ret = '不是正确的ip地址,您可以使用 "/ip ip地址" 进行查找' + else: + rlt = [] + try: + rlt.append('IP: ' + ip) + rlt.append('国家/地区: ' + rem['country']) + rlt.append('ISP: ' + rem['isp']) + rlt.append('ASN: ' + str(rem['asn'])) + rlt.append('ASN组织: ' + rem['asn_organization']) + rlt[1] += ', ' + rem['region'] + rlt[1] += ', ' + rem['city'] + except: + pass + ret = '\n'.join(rlt) + return ret diff --git a/worker/ns.py b/worker/ns.py new file mode 100644 index 0000000..ecbf91d --- /dev/null +++ b/worker/ns.py @@ -0,0 +1,9 @@ +from zzcore import StdAns +import os + +class Ans(StdAns): + def GETMSG(self): + domain = 'www.qq.com' + p = os.popen("nslookup " + domain) + msg = p.read() + return msg \ No newline at end of file diff --git a/worker/yiyan.py b/worker/yiyan.py index b6d0e05..f4bfd93 100644 --- a/worker/yiyan.py +++ b/worker/yiyan.py @@ -12,11 +12,10 @@ class Ans(StdAns): cmd = '' if cmd == '帮助': msg = '您可以使用以下参数:\n 动画,漫画,游戏,文学,原创,来自网络,其他,影视,诗词,网易云,哲学,抖机灵' + elif cmd == '': + msg = requests.get(url).text + elif cmd in cmdlst: + msg = requests.get(url+cmdlst[cmd]).text else: - if cmd == '': - msg = requests.get(url).text - elif cmd in cmdlst: - msg = requests.get(url+cmdlst[cmd]).text - else: - msg = '我不知道 ' + cmd + ' 这个参数,你可以使用"/yiyan 帮助"来获取帮助' + msg = '我不知道 ' + cmd + ' 这个参数,你可以使用"/yiyan 帮助"来获取帮助' return msg \ No newline at end of file