Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy thread is interrupted before the changes are complete
    text
    copied!<p>I'm attempting to create python module for getting MAC adresses by IP addresses.</p> <pre><code>def getMACs(addressesList): def _processArp(pkt): spa = _inet_ntoa(pkt.spa) if pkt.op == dpkt.arp.ARP_OP_REPLY and spa in _cache.macTable: lock.acquire() try: _cache.macTable[spa] = _packedToMacStr(pkt.sha) _cache.notFilledMacs -= 1 finally: lock.release() if _cache.notFilledMacs == 0: thrd.stop() addresses = _parseAddresses(addressesList) _cache.registerCacheEntry("macTable", {}) _cache.registerCacheEntry("notFilledMacs", 0) _events.arpPacket += _processArp lock = threading.Lock() thrd = _CaptureThread(promisc=False, timeout_ms=30, filter="arp") thrd.start() for addr in addresses: if _sendArpQuery(addr): _cache.macTable[str(addr)] = None _cache.notFilledMacs += 1 thrd.join(125) thrd.stop() return _cache.macTable if __name__ == "__main__": macTable = getMACs([IPAddress("192.168.1.1"), IPAddress("192.168.1.3")]) _pprint.pprint(macTable) </code></pre> <p>When I run this module I get</p> <pre><code>{'192.168.1.1': '00:11:95:9E:25:B1', '192.168.1.3': None} </code></pre> <p>When I debug _processArp step by step I get</p> <pre><code>{'192.168.1.1': '00:11:95:9E:25:B1', '192.168.1.3': '00:21:63:78:98:8E'} </code></pre> <p>Class CaptureThread:</p> <pre><code>class CaptureThread(threading.Thread): def __init__ (self, name=None, snaplen=65535, promisc=True, timeout_ms=0, immediate=False, filter=None): threading.Thread.__init__(self) self.__running = True self.__name = name self.__snaplen = snaplen self.__promisc = promisc self.__timeout_ms = timeout_ms self.__immediate = immediate self.__filter = filter def stop(self): self.__running = False def run(self): self.__pc = pcap.pcap(self.__name, self.__snaplen, self.__promisc, self.__timeout_ms, self.__immediate) if self.__filter: self.__pc.setfilter(self.__filter) while self.__running: self.__pc.dispatch(1, self.__processPacket) def __processPacket(self, timestamp, pkt): peth = dpkt.ethernet.Ethernet(pkt) if isinstance(peth.data, dpkt.arp.ARP): _events.arpPacket(peth.data) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload