环境准备
本机环境 ubuntu 17.04,python2.7.13
替换阿里源
wget https://git.io/superupdate.sh bash superupdate.sh
安装相关依赖
apt install python-pip --fix-missing
安装censys
pip install censys
中间过程报错,缺少setuptools,还需要升级一下pip
分别执行以下命令:
pip install setuptools pip install --upgrade pip
然后再次安装censys即成功
pip install censys
测试
官方测试代码
Below is a sample Python script that connects to the API and lists raw datasets that are available for download.
import sys import requests API_URL = "https://censys.io/api/v1" UID = "406dd40f-f68e-42c4-b8e6-6a6078185715" SECRET = "2j7Eoe9RyJLBMXSyLui4fo0a4AJGz3lo" res = requests.get(API_URL + "/data", auth=(UID, SECRET)) if res.status_code != 200: print("error occurred: %s" % res.json()["error"]) sys.exit(1) for name, series in res.json()["raw_series"].items(): print(series["name"], "was last updated at", series["latest_result"]["timestamp"])
Censys Python Library. We also maintain a Python library for interacting with the API, which can be installed with Pip: pip install censys
.
Below is a sample script that iterates over NSS trusted certificates:
import censys.certificates UID = "406dd40f-f68e-42c4-b8e6-6a6078185715" SECRET = "2j7Eoe9RyJLBMXSyLui4fo0a4AJGz3lo" certificates = censys.certificates.CensysCertificates(UID, SECRET) fields = ["parsed.subject_dn", "parsed.fingerprint_sha256", "parsed.fingerprint_sha1"] for c in certificates.search("validation.nss.valid: true", fields=fields): print(c["parsed.subject_dn"])
测试效果