python局域网ip扫描示例分享

yipeiwu_com6年前Python基础

复制代码 代码如下:

#!/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();

相关文章

python cumsum函数的具体使用

这个函数的功能是返回给定axis上的累计和函数的原型如下:详见 doc  numpy.cumsum(a, axis=None, dtype=None, out=None) &n...

Python实现简单的语音识别系统

Python实现简单的语音识别系统

最近认识了一个做Python语音识别的朋友,聊天时候说到,未来五到十年,Python人工智能会在国内掀起一股狂潮,对各种应用的冲击,不下于淘宝对实体经济的冲击。在本地(江苏某三线城市)做...

深入理解Django的自定义过滤器

深入理解Django的自定义过滤器

前言 本文主要给大家介绍了关于Django自定义过滤器的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍: 过滤器与函数 django过滤器的本质是函数,但"函...

Python中print和return的作用及区别解析

print只是为了向用户显示一个字符串,表示计算机内部正在发生的事情。计算机却无法使用该print出现的内容。 return是函数的返回值。该值通常是人类用户看不到的,但是计算机可以在其...

Python求均值,方差,标准差的实例

如下所示: import numpy as np arr = [1,2,3,4,5,6] #求均值 arr_mean = np.mean(arr) #求方差 arr_var = n...