Python实现调用钟馗之眼api查询

代码如下:

import requests, json




access_token = ''
ip_list = []
def saveListToFile(file, list):
    """
        将列表逐行写如文件中
    :return:
    """
    s = '\n'.join(list)
    with open(file, 'w') as (output):
        output.write(s)


def apiTest():
    """
        进行 api 使用测试
    :return:
    """
    global access_token
    page = 1
    headers = {'Authorization': 'JWT ' + access_token}
    print(access_token)
    while True:
        try:
            r = requests.get(url=('https://api.zoomeye.org/host/search?query="xxx"&facet=app,os&page=' + str(page)), headers=headers)
            r_decoded = json.loads(r.text)
            for x in r_decoded['matches']:
                print(x['ip'] + ':' + str(x['portinfo']['port']))
                ip_list.append(x['ip'] + ':' + str(x['portinfo']['port']))

            print('[-] info : count ' + str(page * 10))
        except Exception as e:
            try:
                if str(e) == 'matches':
                    print('[-] info : account was break, excceeding the max limitations')
                    #break
                else:
                    print('[-] info : ' + str(e))
            finally:
                e = None
                del e
        else:
            if page == 100:                                                                 #页数(每页20条)
                break
            page += 1


def login(user,passwd):
    """
        输入用户米密码 进行登录操作
    :return: 访问口令 access_token
    """
    global access_token
    data = {'username':user, 
     'password':passwd}
    data_encoded = json.dumps(data)
    try:
        r = requests.post(url='https://api.zoomeye.org/user/login', data=data_encoded)
        r_decoded = json.loads(r.text)
        access_token = r_decoded['access_token']
    except Exception as e:
        try:
            print('[-] info : username or password is wrong, please try again ')
        finally:
            e = None
            del e
    apiTest()
    saveListToFile('ip.txt', ip_list)
if __name__ == '__main__':username
    login('username','passwd')

 结果:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值