python局域网ip扫描示例分享
代码如下:
#!/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(); 相关推荐
柠檬班 2020-04-22
LczPtr 2020-02-03
程松 2020-01-14
hickwu 2019-12-17
zuiaiqun 2019-12-12
afanti 2019-11-12
Usper 2015-07-30
ZDreamST 2018-06-02
木子李CSDN 2016-11-08
benico 2016-11-04
fsfsdfsdw 2015-07-30
加菲猫园 2014-12-18
linuxhh 2014-01-19
willcoder 2016-09-19
ZoctopusD 2014-11-10
mayflowers 2019-06-28
安得情怀似旧时 2015-02-13
菜鸟上路CCLinux 2014-01-18
scarecrowbyr 2011-11-28