python局域网ip扫描示例分享

代码如下:

#!/usr/bin/python# -*- coding: utf-8 -*-

from scapy.all import *from time import ctime,sleepimport threadingtimeout = 4conf.verb=0

def pro(cc,handle): dst = “192.168.1.” + str(cc) packet = ip(dst=dst, ttl=20)/icmp() reply = sr1(packet, timeout=timeout) if not (reply is none): handle.write(reply.src+” is online”+”\n”) #print reply.src, “is online”

def main(): threads=[] f=open(‘ip.log’,’a’) for i in range(2,254): t=threading.thread(target=pro,args=(i,f)) threads.append(t) print “main thread begins at “,ctime() for t in threads : t.start() for t in threads : t.join() print “main thread ends at “,ctime()

if __name__==”__main__” : main();

发表评论