python局域网ip扫描示例分享

yipeiwu_com5年前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 实现list或string按指定分段

我就废话不多说了,直接上代码吧! #方法一 def list_cut(mylist,count): length=len(mylist) merchant=length//c...

Python小程序之在图片上加入数字的代码

Python小程序之在图片上加入数字的代码

在GitHub上发现一些很有意思的项目,由于本人作为Python的初学者,编程代码能力相对薄弱,为了加强Python的学习,特此利用前辈们的学习知识成果,自己去亲自实现。 来源:Gi...

Python实现的金山快盘的签到程序

复制代码 代码如下:__author__ = 'clownfish'#coding:utf-8import urllib2,urllib,cookielib,json username...

Django自定义过滤器定义与用法示例

本文实例讲述了Django自定义过滤器定义与用法。分享给大家供大家参考,具体如下: 一、自定义过滤器的介绍 前面我们就介绍过过滤器其实就是一个函数,把要过来的字段传递到一个函数内,进行加...

从Python的源码来解析Python下的freeblock

从Python的源码来解析Python下的freeblock

1 引言 在python内存管理中,有一个block的概念。它比较类似于SGI次级空间配置器。 首先申请一块大的空间(4KB),然后把它切割成一小份(8, 16 一直到512)。 当有内...