python局域网ip扫描示例分享
程序员文章站
2023-10-17 20:37:29
复制代码 代码如下:#!/usr/bin/python# -*- coding: utf-8 -*-
from scapy.all import *from time i...
复制代码 代码如下:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from scapy.all import *
from time import ctime,sleep
import threading
timeout = 4
conf.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();