whosonline/netcheck.py
def netcheck_main(network):
    '''Main function of netcheck module called from executable
    '''

    # import logfacility
    # LOGGER = logfacility.build_logger()

    # save results to show notifications if something changes
    results = {}

    # set up network object and build ip strings from it using get_ips filter
    network_obj = ipaddress.ip_network(network, strict=True)
    ip_addresses = [str(address_obj) for address_obj in get_ips(network_obj)]

    # get the network device responsible for given network
    netdevice = get_netdevice(network.split('/')[0])  # cut off cidr netmask

    # get local hostname to add to OMIT_HOSTS list
    local_hostname = socket.gethostname()
    OMIT_HOSTS.append(local_hostname)

    # abort if not device can be found
    assert netdevice, "Unable to find network device belonging to network %s" % network
    print('Device associated to network %s : %s' % (network, netdevice))

    # main loop
    while True:
        for ip_str in ip_addresses:
            hostname = get_hostname(ip_str)
            if hostname and hostname not in OMIT_HOSTS:
                last_result = results.get(hostname)
                ping_result = arping(ip_str, netdevice)  # or ping(hostname)
                # notify if status changes --> DEACTIVATED!
                if (last_result is not None) and (last_result != ping_result):
                    notify(hostname, 'Online' if ping_result else 'Offline')
                # save new result
                if hostname not in results:
                    notify('New host found!', hostname)
                results[hostname] = ping_result
                # LOGGER.info('Host %s online: %s' % (hostname, ping_result))
                print('Host %s online: %s' % (hostname, ping_result))
Main function of netcheck module called from executable
    
Main function of netcheck module called from executable
Main function of netcheck module called from executable
def netcheck_main(network):
    results = {}
    network_obj = ipaddress.ip_network(network, strict=True)
    ip_addresses = [str(address_obj) for address_obj in get_ips(network_obj)]
    netdevice = get_netdevice(network.split('/')[0])  
    local_hostname = socket.gethostname()
    OMIT_HOSTS.append(local_hostname)
    assert netdevice, "Unable to find network device belonging to network %s" % network
    print('Device associated to network %s : %s' % (network, netdevice))
    while True:
        for ip_str in ip_addresses:
            hostname = get_hostname(ip_str)
            if hostname and hostname not in OMIT_HOSTS:
                last_result = results.get(hostname)
                ping_result = arping(ip_str, netdevice)  
                if (last_result is not None) and (last_result != ping_result):
                    notify(hostname, 'Online' if ping_result else 'Offline')
                if hostname not in results:
                    notify('New host found!', hostname)
                results[hostname] = ping_result
                print('Host %s online: %s' % (hostname, ping_result))
def netcheck_main ( network ) : results = { } network_obj = ipaddress . ip_network ( network , strict = True ) ip_addresses = [ str ( address_obj ) for address_obj in get_ips ( network_obj ) ] netdevice = get_netdevice ( network . split ( '/' ) [ 0 ] ) local_hostname = socket . gethostname ( ) OMIT_HOSTS . append ( local_hostname ) assert netdevice , "Unable to find network device belonging to network %s" % network print ( 'Device associated to network %s : %s' % ( network , netdevice ) ) while True : for ip_str in ip_addresses : hostname = get_hostname ( ip_str ) if hostname and hostname not in OMIT_HOSTS : last_result = results . get ( hostname ) ping_result = arping ( ip_str , netdevice ) if ( last_result is not None ) and ( last_result != ping_result ) : notify ( hostname , 'Online' if ping_result else 'Offline' ) if hostname not in results : notify ( 'New host found!' , hostname ) results [ hostname ] = ping_result print ( 'Host %s online: %s' % ( hostname , ping_result ) )
Main function of netcheck module called from executable
Main function of netcheck module called from executable
'''Main function of netcheck module called from executable
    ''' # import logfacility # LOGGER = logfacility.build_logger() # save results to show notifications if something changes # set up network object and build ip strings from it using get_ips filter # get the network device responsible for given network # cut off cidr netmask # get local hostname to add to OMIT_HOSTS list # abort if not device can be found # main loop # or ping(hostname) # notify if status changes --> DEACTIVATED! # save new result # LOGGER.info('Host %s online: %s' % (hostname, ping_result))
network