- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我一直在研究一个 Python 程序,该程序搜索多个 IP 地址范围并检查 SSL 证书/从中读取某些信息,然后将其写入 CSV 文件。
我现在遇到的问题是,我要搜索的某些 IP 地址可能在同一个 IP 地址上有多个域名。我一直在四处寻找并尝试为此提出某种解决方案,但似乎没有太多关于在 OpenSSL 中使用 SNI 检查 IP 地址的文档
此外,我遇到的另一个问题是我想从证书中获取服务器类型(例如 apache、nginx 等),但 OpenSSL 似乎没有提供该信息。另一方面,Curl 确实如此,我实际上是在使用 curl 来确定是否在 IP 地址上找到了证书——我只是不知道如何从 curl 的输出中获取该信息。
如果有人可以就如何实现上面列出的两个功能提供一些意见,我将不胜感激
这是我目前的代码(请原谅真正长的硬编码线程——我还没有机会清理它):
from subprocess import *
import time
import ssl
import OpenSSL
import threading
import sys
import csv
def main():
global IP_list
IP_list = []
global certInfoHolder
certInfoHolder = []
getRanges()
def getRanges():
print 'Enter a range(ex. From: 192.168.1.0 , To: 192.168.1.10)'
starting_IP = raw_input('From: ')
ending_IP = raw_input('To: ')
ip_ranges = ipRange(starting_IP, ending_IP)
addMore = raw_input('Do you want to add another IP range?Y/N')
addmore = addMore.lower()
if addMore == 'y' or addMore == 'yes':
getRanges()
elif addMore == 'n' or addMore =='no':
print 'Done gathering IP Addresses'
createdThreads = 0
threadSplit = len(IP_list) / 10
#Splitting the work up between the threads
thread_1_list = IP_list[0:threadSplit]
thread_2_list = IP_list[threadSplit:(threadSplit*2)]
thread_3_list = IP_list[(threadSplit*2):(threadSplit*3)]
thread_4_list = IP_list[(threadSplit*3):(threadSplit*4)]
thread_5_list = IP_list[(threadSplit*4):(threadSplit*5)]
thread_6_list = IP_list[(threadSplit*5):(threadSplit*6)]
thread_7_list = IP_list[(threadSplit*6):(threadSplit*7)]
thread_8_list = IP_list[(threadSplit*7):(threadSplit*8)]
thread_9_list = IP_list[(threadSplit*8):(threadSplit*9)]
thread_10_list = IP_list[(threadSplit*9):(threadSplit*10)]
print '5 Threads..Splitting the work up to: ' , threadSplit
for address in range(threadSplit):
print address
thread_1 = getCertInfo(thread_1_list[address])
thread_2 = getCertInfo(thread_2_list[address])
thread_3 = getCertInfo(thread_3_list[address])
thread_4 = getCertInfo(thread_4_list[address])
thread_5 = getCertInfo(thread_5_list[address])
thread_6 = getCertInfo(thread_6_list[address])
thread_7 = getCertInfo(thread_7_list[address])
thread_8 = getCertInfo(thread_8_list[address])
thread_9 = getCertInfo(thread_9_list[address])
thread_10 = getCertInfo(thread_10_list[address])
thread_1.start()
thread_2.start()
thread_3.start()
thread_4.start()
thread_5.start()
thread_6.start()
thread_7.start()
thread_8.start()
thread_9.start()
thread_10.start()
thread_1.join()
thread_2.join()
thread_3.join()
thread_4.join()
thread_5.join()
thread_6.join()
thread_7.join()
thread_8.join()
thread_9.join()
thread_10.join()
if address == threadSplit-1:
for address in range(threadSplit,len(thread_5_list)):
thread_10 = getCertInfo(thread_10_list[address])
thread_10.start()
thread_10.join()
c = csv.writer(open("AInfo.csv", "a"))
CIH = certInfoHolder
for info in CIH:
c.writerow([info[0], info[1], info[2], info[3], info[4]])
print 'DONE'
def ipRange(start_ip, end_ip):
start = list(map(int, start_ip.split(".")))
end = list(map(int, end_ip.split(".")))
temp = start
IP_list.append(start_ip)
while temp != end:
start[3] += 1
for i in (3, 2, 1):
if temp[i] == 256:
temp[i] = 0
temp[i-1] += 1
IP = ".".join(map(str, temp))
IP_list.append(IP)
print 'IP_List size', len(IP_list)
class getCertInfo(threading.Thread):
def __init__(self,IP):
threading.Thread.__init__(self)
self.IP_check=IP
def run(self):
try:
#Using curl to check for a timeout
self.getCert = check_output('curl --max-time 2 '+self.IP_check,
stderr=STDOUT,
shell=True)
#OpenSSL get server certificate
self.server_certificate = ssl.get_server_certificate((self.IP_check, 443))
self.x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, self.server_certificate)
#Formatting expiration date and time
self.eDateT = str(self.x509.get_notAfter())
#173.252.110.27
self.certInfo = self.x509.get_subject()
self.commonName = self.certInfo.commonName
self.companyName = self.certInfo.O
self.serialNumber = self.x509.get_serial_number()
self.x = [str(self.IP_check),str(self.companyName),str(self.eDateT),
str(self.commonName),str(self.serialNumber)]
certInfoHolder.append(self.x)
except CalledProcessError as detail:
print str(detail) + ' ' + self.IP_check +'\n'
pass
最佳答案
SNI
如果我理解正确的话,你应该能够使用 Python 3.x 系列、3.2+ 达到目标。
如果您坚持使用 Python 2,请查看 python-requests 对两个可选依赖项 ndg-httpsclient
和 pyasn1
的作用。
我的理解是,由于开发人员令人困惑的观点 SNI is somehow a feature of Python,您不能使用 <= 2.7.8 的普通 Python 做很多事情。
编辑
感谢PEP466 , Python 2.7.9 包含从 Python 3.4 向后移植的 ssl 模块,您拥有所有 OpenSSL 功能。
其他项目
也许 sslyze (github)已经可以做你想做的事了吗?
关于python - 在 Python 中获取服务器/服务器名称指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17197378/
我正在尝试复兴使用3DNow的旧Win32游戏!指令集以进行3D渲染。 在Win7-Win10等现代OS上,不允许FPADD或FPMUL之类的Win10指令,并且该程序将引发异常。 自3DNow数量!
我坐在机场这里,想出了一些我想尝试的东西,但如果 macports 下载-编译-下载-编译,我没有时间 sudo port install .但是,如果它下载了所有内容,那么我就可以在飞机上对其进行编
我使用的是 Jackson 库,而不是 2.6.3。我想在类中定义序列化方法,并且我想指示 Jackson 在序列化对象时调用此方法。 例如 public interface AClass { d
我正在制作一个自动目录,一切正常。我只需要将顶部标题指定为“粗体” jQuery(document).ready(function(){ var ToC = "" + ""; var ne
我要设置 html 对象的属性。 var property1 = 'style.visibility'; var property2 = 'style.display'; var property3
在 boost::spirit::traits::transform_attribute 中指示解析失败的正确方法是什么?我可以抛出任何旧的异常,还是它要我做的特定事情? namespace boos
我正在使用 XmlPullParser 在移动设备上通过 http 逐渐加载一些数据。 由于此类连接的速度通常可以低至 1KB/s 或更低,我想降低 PullParser 的默认缓冲区大小 8096
我正在尝试集体检查数据是否存在于各个表中。我有一个主表 A 和包含与 A 相关的数据的各种表 - 称它们为表 B、C 和 D。我想编写一个查询,对于 A 中的每个条目,指示是否有任何行在 B、C 和
当您使用 Cargo 和 rustdoc 为 Rust crate 生成文档时,我在生成的页面中看不到任何指示它适用于哪个版本的 crate。例如,看看 the log crate's documen
我有一个 CS 类,它表示 3D 坐标系,即 (x, y, z) class CS { private: double x; double y; d
我有一个用 Wordpress 制作的项目。我有在社交网络上分享的帖子。在推特上没有问题,因为我创建的推文没有图片。Facebook 允许我从要分享的链接中选择页面图像。但是 Google+ 正在挑选
问题 如何在 Scrapy 中忽略响应的内容长度? 解释 考虑这个 curl 命令" curl -u http://data.icecat.biz/export/level4/NL/files.in
我有一个测试程序,如果它可以依赖于在 Windows 上以严格的优先级顺序安排的线程,它会简单得多。我看到一个低优先级线程与高优先级线程一起运行,我想知道这是不是因为不同的线程被安排在不同的处理器内核
我正在使用 getUserMedia 函数从网络摄像头录制视频。一切正常,除了它仅以 640x480 分辨率录制,当我刚刚指定 video: true 作为约束时。 如果我按如下方式设置约束,我现在可
我有一个简单的类定义如下: class Model { constructor(props?:{}) { _extend(props, this); } } 其中构造函数接受一个对象作
我第一次在 Visual Studio 2010 beta 2 中使用 .net-4.0 中的 System.ComponentModel.Composition 试用托管扩展框架。 我一直无法让 C
我正在使用 System.CodeDom 功能在运行时编译代码,我想知道我是否可以指定一个编译器参数或其他解决方法来以英语语言显示编译器错误,而不是使用系统的默认语言语言。 但是,在 MSDN 文档中
我正在使用 XmlWriterSettings 将 Xml 写入文件。我有只有属性的元素,没有 child 。我希望它们输出为: 代替 我可以使用 XmlWriterSettings 来实现吗?
我在 sbt 中创建了一个多项目构建。这是 build.sbt 在主目录中: lazy val root = project in file(".") aggregate(data, reco, re
这里我有一个程序,可以计算一个人不同的日常事件,例如他一周踢足球的次数等。这里我有一个 switch 语句,可以计算不同事件的值。我强制这个对象指示 sort() 函数内的 dayEvents 对象。
我是一名优秀的程序员,十分优秀!