码迷,mamicode.com
首页 > 编程语言 > 详细

python调用censys接口进行ipv4查询

时间:2018-08-28 13:00:55      阅读:429      评论:0      收藏:0      [点我收藏+]

标签:查询   pass   res   on()   protoc   www.   def   result   com   

def censysApi(searchQuery):
    API_URL = "https://www.censys.io/api/v1"
    UID = "51645b5b-b129-499f-a008-c7cf602ed76b"
    SECRET = "xJVPTgyQmgNb8O8JdGYZZOJw8MBk0RtT"
    dataFirstForPage = {
        "query": searchQuery,
        "page": 1,
        "fields": []
    }

    resData = requests.post(API_URL + "/search/ipv4", data=json.dumps(dataFirstForPage),auth=(UID, SECRET),headers=headers)
    resultForPage = resData.json()
    pages = int(resultForPage[‘metadata‘][‘pages‘])
    try:
        for page in range(1,pages+1):
            data = {
                "query": searchQuery,
                "page": page,
                "fields": ["ip","protocols"]
            }
            sleep(1)
            req = requests.post(API_URL + "/search/ipv4", data=json.dumps(data), auth=(UID, SECRET))
            resForResult = req.json()

            for result in resForResult["results"]:
                print result[‘ip‘]+","+result[‘protocols‘]
    except:
        pass

censysApi("baidu.com")

  

python调用censys接口进行ipv4查询

标签:查询   pass   res   on()   protoc   www.   def   result   com   

原文地址:https://www.cnblogs.com/websec/p/9547412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!