python 自动 openssl 检查
python automatic openssl check
我想用我的脚本检查来自不同网络服务的多个 SSL 证书。每个服务的 url 应该从文件中读取。如果我在 get_server_certificate
函数中使用 adr
它将起作用,但如果想使用 list_adr
它将产生以下错误。
我的代码:
import OpenSSL
import ssl
class certcheck_test:
#adr = ('www.google.com', 443)
while 1:
f = open("C:/tmp/test.txt", "r")
list_adr = f.readline()
f.close()
print list_adr
cnt = 0
cert = ssl.get_server_certificate(list_adr)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
data = x509.get_notAfter()
test.txt 文件:
('www.google.com',443)
('www.google.com',443)
('www.google.com',443)
错误:
File "####/PycharmProjects/Zertifikat/certcheck_test.py", line 4, in <module>
class certcheck_test:
File "####/certcheck_test.py", line 12, in certcheck_test
cert = ssl.get_server_certificate(list_adr)
File "####\Python27\Lib\ssl.py", line 1008, in get_server_certificate
host, port = addr
ValueError: too many values to unpack
- 逐行读取文件。
- 从行中提取服务器和端口名称
- 对于每个服务器和端口 运行 所需的命令
with open("C:/tmp/test.txt", "r") as f:
for line in f:
server = line.split("'")[1]
port = line.split(",")[1].split(")")[0]
list_adr=(server, port)
cert = ssl.get_server_certificate(list_adr)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
data = x509.get_notAfter()
我想用我的脚本检查来自不同网络服务的多个 SSL 证书。每个服务的 url 应该从文件中读取。如果我在 get_server_certificate
函数中使用 adr
它将起作用,但如果想使用 list_adr
它将产生以下错误。
我的代码:
import OpenSSL
import ssl
class certcheck_test:
#adr = ('www.google.com', 443)
while 1:
f = open("C:/tmp/test.txt", "r")
list_adr = f.readline()
f.close()
print list_adr
cnt = 0
cert = ssl.get_server_certificate(list_adr)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
data = x509.get_notAfter()
test.txt 文件:
('www.google.com',443)
('www.google.com',443)
('www.google.com',443)
错误:
File "####/PycharmProjects/Zertifikat/certcheck_test.py", line 4, in <module>
class certcheck_test:
File "####/certcheck_test.py", line 12, in certcheck_test
cert = ssl.get_server_certificate(list_adr)
File "####\Python27\Lib\ssl.py", line 1008, in get_server_certificate
host, port = addr
ValueError: too many values to unpack
- 逐行读取文件。
- 从行中提取服务器和端口名称
- 对于每个服务器和端口 运行 所需的命令
with open("C:/tmp/test.txt", "r") as f:
for line in f:
server = line.split("'")[1]
port = line.split(",")[1].split(")")[0]
list_adr=(server, port)
cert = ssl.get_server_certificate(list_adr)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
data = x509.get_notAfter()