[英]Python Threading socket
I'm trying to implement a threading functionality for this answer : Scanning a Class C network Python 我正在尝试为该答案实现线程功能: 扫描C类网络Python
So far i have something like this: 到目前为止,我有这样的事情:
...[snip]..
m = re.search("/", str(host))
if m :
net,_,mask = host.partition('/')
mask = int(mask)
net = atod(net)
for host in (dtoa(net+n) for n in range(0, 1<<32-mask)):
try:
mycustomsocket(host)
except:
print host+" is down"
pass
else:
mycustomsocket(host)
What I'm looking for, would be to open 255 thread to scan all hosts parsed with mycustomsocket() at once, for speed issues. 我正在寻找的是打开255线程来一次扫描所有用mycustomsocket()解析的主机,以查找速度问题。
Any help would be greatly appreciated ! 任何帮助将不胜感激 !
我认为他确实给了您答案,请先阅读文档,然后在对实现线程代码有特定疑问时再回来...如果您阅读已经提到的关于devshed的文章,则可以看到如何创建自己的线程类并将您要使用的IP地址传递到线程中,然后将您的工作代码与某种线程安全队列一起放在该线程中,线程可以在其中放回您所需要的任何信息。
I once wrote a multi-threaded port scanner . 我曾经写过一个多线程端口扫描器 。 Feel free to use it for some ideas on improving performance.
随意将其用于改善性能的一些想法。 Over time, it has been improved and refactored such that it doesn't provide a concise example, but instead implements a more robust implementation with re-usable components.
随着时间的流逝,它已经得到了改进和重构,因此它没有提供简洁的示例,而是使用可重用的组件实现了更强大的实现。 I hope the core ideas aren't masked by the abstraction.
我希望抽象不要掩盖核心思想。
This question is not very specific. 这个问题不是很具体。 It sounds like: "I need threading support for my code, please do the work for me."
听起来像:“我需要代码的线程支持,请为我完成工作。”
Please read the docs about threading in Python and related topics like the Queue class. 请阅读有关Python中的线程的文档以及诸如Queue类之类的相关主题。 If you have a more specifc question, come back and ask again.
如果您还有其他特定问题,请再次询问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.