コード例 #1
0
def scan():
    """
    Scan the network

    Args:
        None
    Returns:
        None
    """
    print("SCAN")
    local_scanner = network_scan.NetworkScanner(network_scan.get_local_ip())
    arp_output = local_scanner.get_devices_on_network("-sn", "-a -n")
    ips = local_scanner.format_to_get_ip(arp_output)[:-2]
    macs = local_scanner.format_to_get_mac(arp_output)[:-2]
    vendors = local_scanner.get_vendor_by_mac(macs)
    mobile, iphone, android = network_scan.NetworkScanner.detect_mobile(ips)
    print(arp_output)
    print(ips)
    print(macs)
    print(vendors)

    for i in range(len(ips)):
        device = Device()
        device.ip_address = ips[i]
        device.mac_address = macs[i]
        device.vendor = vendors[i]
        device.mobile = mobile[i]
        device.port = 22
        device, created = Device.objects.update_or_create(
            ip_address=device.ip_address,
            mac_address=device.mac_address,
            vendor=device.vendor,
            mobile=device.mobile,
            port=device.port)
コード例 #2
0
    ip_address = str(process.read())[:-1]  #Removes the space at the end
    return ip_address


local_device_ip = get_local_ip()
local_scanner = NetworkScanner(get_local_ip())
arp_output = local_scanner.get_devices_on_network("-sn", "-a -n")
ips = local_scanner.format_to_get_ip(arp_output)[:-2]
# ips = local_scanner.check_if_identifier_broadcast(ips)
macs = local_scanner.format_to_get_mac(arp_output)[:-2]
vendors = local_scanner.get_vendor_by_mac(macs)
mobile, iphone, android = NetworkScanner.detect_mobile(ips)
ports_open = local_scanner.detect_open_common_ports(ips)
print(arp_output)
print(ips)
print(macs)
print(vendors)

for i in range(len(ips)):
    device = Device()
    device.ip_address = ips[i]
    device.mac_address = macs[i]
    device.vendor = vendors[i]
    device.mobile = mobile[i]
    device.port = ports_open[i]
    device, created = Device.objects.update_or_create(
        ip_address=device.ip_address,
        mac_address=device.mac_address,
        vendor=device.vendor,
        mobile=device.mobile,
        port=device.port)