Ping all IP addresses in a network

Please refer the following script for, ping the Ip-addresses in the network and it shows whether the corresponding Ip-addresses is offline or online.




import os
import re
def ecmd(CMD, r=True):
    import ctypes
    class disable_file_system_redirection:
        _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
        _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
        def __enter__(self):
            self.old_value = ctypes.c_long()
            self.success = self._disable(ctypes.byref(self.old_value))
        def __exit__(self, type, value, traceback):
            if self.success:
                self._revert(self.old_value)
    from subprocess import PIPE, Popen
    with disable_file_system_redirection():
        OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = OBJ.communicate()
    ret=OBJ.returncode
    if r:
        return ret
    else:            
        if ret==0:
            return out
        else:
            return ret



a=os.popen('arp -a').read()
reg=re.findall('([0-9]{2}.[0-9]{3}.[0-9]{2}.[0-9]+)',a)
length= len(reg)
print 'The total number of IPADDRESSES present in your netwrok is: %d' %length
print '
'
print 'The following IP ADDRESSES in your network went OFFLINE  :'
for i in reg:
    c='ping %s'%i
    if ecmd(c, True)!=0:
        print '%s is offline'%i

print '
'
print 'The following IP ADDRESSES in your network went ONLINE  :'
for i in reg:
    if ecmd(c, True)==0:
        print '%s is online'%i


SAMPLE OUTPUT:

20170524-ip_monitoring.json (2.05 KB)

I’m not sure why, but I keep getting:

2017/05/25 05:23:01 PM Finished success The total number of IPADDRESSES present in your network is: 0 The following IP ADDRESSES in your network went OFFLINE : The following IP ADDRESSES in your network went ONLINE :

…on any host I run on, whether logged in user or system user. Anyone else have this issue?

Hi @computerexperts

We will check the script from our side and update you.

Thanks