# from https://bbs.archlinux.org/viewtopic.php?id=61009 # MOD KLL from socket import * network = '192.168.1.' port = 80 # 135 import os from subprocess import Popen, PIPE #__________________________________________________________ def is_up(addr): s = socket(AF_INET, SOCK_STREAM) s.settimeout(0.10) ## set a timeout of 0.01 sec /KLL set 0.1 if not s.connect_ex((addr,port)): # connect to the remote host on port 'port' s.close() return 1 else: s.close() #__________________________________________________________ def run(): print '' for ip in xrange(1,256): ## 'ping' addresses 192.168.1.1 to .1.255 addr = network + str(ip) if is_up(addr): result = Popen(['arp', '-a', addr], stdout=PIPE, stderr=PIPE, shell=False) outp, errp = result.communicate() # thats a big wait MAC = "" if (outp.find(addr) >= 0) : posi = outp.find(addr) + 20 MAC = outp[posi:posi+20] print '%s \t- %s MAC: %s' % (addr, getfqdn(addr),MAC) ## the function 'getfqdn' returns the remote hostname # KLL no, only for my own PC?? #__________________________________________________________ if __name__ == '__main__': print ' scanning network %s for port %s' % (network,port) run() print 'Done'