python局域网ip扫描示例分享

时间:2021-05-22

复制代码 代码如下:
#!/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();

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章