Sep-01-2019, 06:27 AM
I've simplified my question a bit here to see if anyone can help me with this. When I run the following IP Scan, the results print fine from within the callback function. The whole list will even appear if I do a print() of self.mac_list from within the callback function. However, when the routine terminates and go() returns self.mac_list it is always empty. Anyone know what I am missing here?
Thanks,
Jim
Thanks,
Jim
import nmap class IP_Roam(): def __init__(self, root_ip="", display_on=False): self.mac_list = [] def callback_result(host, scan_result): print(scan_result) self.mac_list.append(scan_result) def go(): nma = nmap.PortScannerAsync() nma.scan(hosts='192.168.1.0/30', arguments='-sP', callback=callback_result) while nma.still_scanning(): print("Waiting >>>") nma.wait(2) # you can do whatever you want but I choose to wait after the end of the scan return self.mac_list if __name__ == "__main__": ps = IP_Roam() results = ps.go() print(results)