python调用censys接口进行ipv4查询

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")

  

posted @ 2018-08-28 12:13 webappsec93 阅读(...) 评论(...) 编辑 收藏