def collection5(): collection = VMRecordCollection() collection.append( VMRecord("192.168.0.1", "00:00:00:e0:00:08", "Host 3")) collection.append( VMRecord("192.168.0.2", "00:00:00:f7:9d:df", "Host 2")) return collection
def collection0(): collection = VMRecordCollection() collection.append( VMRecord("192.168.0.1", "00:00:00:c0:00:08", "Host 1")) collection.append( VMRecord("192.168.0.2", "00:00:00:f7:9d:df", "Host 1")) collection.append( VMRecord("192.168.0.254", "00:00:00:ff:76:17", "Host 1")) return collection
def scan(): from scapy.all import srp, Ether, ARP, conf import socket conf.verb = 0 ans, uans = srp(Ether(dst="FF:FF:FF:FF:FF:FF") / ARP(pdst=VMSettings.ip_range), timeout=2, iface=VMSettings.interface_to_scan, inter=0.1) collection = VMRecordCollection() for snd, rcv in ans: hostIP = rcv.sprintf("%ARP.psrc%") hostMAC = rcv.sprintf("%Ether.src%") try: host = socket.gethostbyaddr(hostIP) except: host = ('unknown', [], [hostIP]) pass new_rec = VMRecord(hostIP, hostMAC, host[0]) collection.append(new_rec) return collection
def parse_arp_line(arp_line): if len(arp_line) == 0: ArpDump.printout("Error: parse_arp_line: arp_line length is 0") return arp_params = arp_line.split("\t") if len(arp_params) != 3: ArpDump.printout( "Error: parse_arp_line: arp_params length is not 3") return new_vm = VMRecord(arp_params[0], arp_params[1], arp_params[2]) return new_vm
def load_collection(): if not DBLayer.is_connected(): return 0 collection = VMRecordCollection() try: c = DBLayer.connection.cursor() res = c.execute("select ip, mac, name from vms_current") for item in res: item = VMRecord(item[0], item[1], item[2]) collection.append(item) except Exception as ex: ArpDump.printout( "DBCurrent.load_collection: unable to load collection") return collection