# from https://code.google.com/p/jaccon-ipscanner/source/browse/ipscanner.py # mod KLL import os import time from subprocess import Popen, PIPE devnull = open(os.devnull, 'wb') #print "Jaccon Ping Scan 0.1" #print "... type enter to continue " #raw_input() #str1=raw_input("Enter the ip range ( ex: 192.168.0 ) ") #KLL i work with one network only net='192.168.1' prerr=0 # 0 1 print error lines sysswitch=0 # _________________________________________________________________ def varinit(): global sysswitch if os.name == 'nt': # win sysswitch=2 if os.name == 'posix': # RPI linux sysswitch=1 # _________________________________________________________________main varinit() print "scanning ip range ",net #print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" if net == "": print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-" print "please type your ip range and try again..." print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" import sys sys.exit() p = [] # ip -> process act = 0 nrp = 0 err = 0 for n in range(1,255): # start ping processes ip = net+".%d" % n if (sysswitch == 1 ) : # linux p.append((ip, Popen(['ping', '-c', '3', ip], stdout=devnull))) if (sysswitch == 2 ) : # win result = Popen(['ping', '-n', '1', ip], stdout=PIPE, stderr=PIPE, shell=False) outp, errp = result.communicate() if (outp.find("TTL") >=0 ) : print 'Ip: %s active' % (ip) act += 1 elif (outp.find("unreachable") >=0 ) : nrp += 1 else: #like timeout... err += 1 p.append((ip, result)) while p: for i, (ip, proc) in enumerate(p[:]): if proc.poll() is not None: # ping finished p.remove((ip, proc)) # this makes it O(n**2) #print proc.returncode if (sysswitch == 1 ) : if proc.returncode == 0: print('%s active' % ip) act = act + 1 elif proc.returncode == 2: print('%s no response' % ip) nrp = nrp + 1 else: if ( prerr == 1 ) : # KLL short list print '%s error, code: %s' % (ip,proc.returncode) err = err + 1 time.sleep(.04) devnull.close() #print "" #print "IPSCAN PYTHON . powered by @jaccon" #print "" #import os #print "Current OS:",os.name print "OS: %s, Network %s, status active: %s, error: %s, norespones: %s" % ( os.name,net,act,err,nrp ) #print "Active ips [ ",act," ]" #print "Error ips [ ",err," ]" #print "No response [ ",nrp," ]" #print "" #print "Good bye!"