调用ZoomEye API获取信息

摘要:
最近,我一直在提高我的编程能力,并使用一些实用工具进行练习。该脚本使用python语言,主要涉及模块urllib、json和osbreakquery=input#检查包的剩余数量ifquery=='-r':req=urllib。要求Requestida=打开。read()请求。add_headerre=urllib.request.urlopenae=ae=target=json。loadsdict_web=ae['resources']['web-search']dict_host=ae['资源']['host-search']printprintelse:try:req=urllib.request。请求('https://api.zoomeye.org/%s/search?

最近在提高自己编程能力,拿一些实用的小工具练下。该脚本为python语言,主要涉及模块urllib,json,os模块。

功能:调用ZoomEye API获取信息

importurllib.request
importjson
importos

deflogin():
        username = input("username:")
        password = input("password:")
        url = "https://api.zoomeye.org/user/login"data = json.dumps({'username':username,'password':password})
        data_bytes = bytes(data,'utf8')
        try:
                req =urllib.request.Request(url,data_bytes)
                response =urllib.request.urlopen(req)
                html = response.read().decode('utf-8')
                target =json.loads(html)
                
                access_token = target['access_token']
                with open('access_token.txt','w') as f:
                        f.write(access_token)
                        f.close
                        print('login seccess !!!')
                #print('your access_token is:%s'%(access_token))
        exceptException as err:
                print('[info]:username or password is wrong !')
                

defapiget():
        whileTrue:
                host_or_web = input("search for host or web:(‘q!’Sign out):")
                if host_or_web == 'q!':
                        breakquery = input("input your keyword(-r for your resources-info):")  #查看自己的套餐剩余量
                if query == '-r':
                        req = urllib.request.Request('https://api.zoomeye.org/resources-info')
                        ida = open('access_token.txt').read() 
                                
                        req.add_header('Authorization','JWT %s'%(ida))
                        re =urllib.request.urlopen(req)
                        ae = (re.read().decode('utf-8'))
                        ae = target =json.loads(ae)
                        dict_web = ae['resources']['web-search']
                        dict_host = ae['resources']['host-search']
                        print('your web search:%s'%(dict_web))
                        print('your host search:%s'%(dict_host))
                else:
                        try:
req
= urllib.request.Request('https://api.zoomeye.org/%s/search?query=%s'%(host_or_web,query)) idb = open('access_token.txt').read() req.add_header('Authorization','JWT %s'%(idb)) r =urllib.request.urlopen(req) a = (r.read().decode('utf-8')) a = target =json.loads(a) print('tatal:%s'%(a['total'])) for i in range(len(a['matches'])): print (a['matches'][i]['ip']) exceptException as err: print('[erro]:Please enter the correct syntax !') defstart(): if not os.path.isfile('access_token.txt'): #首次使用会检查脚本目录下access_token.txt文件,没有的话登录会创建 print('[info]:you need login') login() apiget() if __name__ == '__main__'
: start()

调用ZoomEye API获取信息第1张

调用ZoomEye API获取信息第2张

免责声明:文章转载自《调用ZoomEye API获取信息》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Liferay7开发体系简介YAML简述下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

nginx --反向代理配置文件

配置文件如下图   server { listen 8080; server_name 0.0.0.0;//这里可以配置相应域名 root /www/facei; index index.html index.htm; access_log /var/log/nginx/facei.access.l...

access数据库删除两个日期之间 的数据 SQL语句

sql2005中sql语句为 DELETE FROM table WHERE ([date] BETWEEN '2011 - 9 - 19 0 : 00 : 00 ' AND '2011 - 9 - 20 0 : 00 : 00') 词语法是正确的,发现再access中没有影响相关行数,解决方法在日期前后加上#,语法为: delete from table...

跨域问题及CORS解决跨域问题方法

1.跨域问题 1.1什么是跨域 跨域是指跨域名的访问,以下情况都属于跨域: 跨域原因说明 示例 域名不同 www.jd.com与www.taobao.com 域名相同,端口不同 www.jd.com:8080与www.jd.com:8081 二级域名不同 item.jd.com与miaosha.jd.com 如果域名和...

Mdb文件工具类,UCanAccess使用,Access数据库操作

================================ ©Copyright 蕃薯耀 2020-01-09 https://www.cnblogs.com/fanshuyao/ 使用Ocbc连接是区分电脑是32位还是64位的,需要安装相应的驱动文件,不方便,所以采用第三方的Jar包(UCanAccess) UCanAccess-4.0.4-bin...

公众号开发笔记二

前言 微信公众平台开发模板消息,用于公众号向用户发送服务通知,如学生进校门,用校卡滴,就可以在公众号接收服务通知,表明学生进校.在公众号内申请功能,添加模板消息. 只有认证后的服务号才能申请模板消息,需要选择2个行业,MP(维基百科,自由的百科全书),模板消息需要模板的ID,和模板中各种参数,内容以".DATA"结尾,否则视为保留字,模板保留符号"{{...

c#使用access数据库时 模糊查询 like 通配符的写法

access通配符为*和? sqlserver通配符为%和_ 在access中使用sql查询语句,进行模糊查询要用:select * from table where name like '*海*' 而在c#中调用该语句却得不到结果,解决办法是c#中使用下面语句:select * from table where name like '%%海%%'...