有几次我看到提到异步 ping 最好使用 twisted。
我在线程上编写了实现(比如Ping a site in Python?)
但是在〜200个线程上我迷恋
在http://twistedmatrix.com/trac/wiki/ProjectsUsingTwisted页面上,我找到了 txNetTools - Ping、traceroute、icmp 等,在 Twisted 中实现,以及为那些想要构建自己的网络工具的人提供的库。
有人用过这个库吗?
我尝试使用它 ping.py:
Traceback (most recent call last):
File "ping.py", line 23, in <module>
class Pinger(ICMP):
NameError: name 'ICMP' is not defined
如果改变:
class Pinger(**ICMP**):
至
class Pinger():
Traceback (most recent call last):
File "ping.py", line 54, in <module>
reactor.listenICMP(0, Pinger())
File "./txnet/reactor.py", line 21, in listenICMP
p.startListening()
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/udp.py", line 102, in startListening
self._connectToProtocol()
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/udp.py", line 123, in _connectToProtocol
self.protocol.makeConnection(self)
AttributeError: Pinger instance has no attribute 'makeConnection'
也许我做错了什么或不明白?
PS扭曲12.0