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生成excel的实例代码

本文实例为大家分享了python生成excel的具体代码,供大家参考,具体内容如下 #_*_coding:utf-8_*_ import MySQLdb import xlwt f...

python3 实现对图片进行局部切割的方法

python3 实现对图片进行局部切割的方法

先拿个图片举例子,比如说截取途中方框内的图片: # 导入相关的库 from PIL import Image # 打开一张图 img = Image.open('test.jpg'...

对numpy中数组元素的统一赋值实例

Numpy中的数组整体处理赋值操作一直让我有点迷糊,很多时候理解的不深入。今天单独列写相关的知识点,进行总结一下。 先看两个代码片小例子: 例子1: In [2]: arr =np....

在python中实现同行输入/接收多个数据的示例

在python中实现同行输入/接收多个数据的示例

在使用python去AC题时总会遇到这样的问题,题目要求同行输入一组数据,但是你使用input时却不能做到,导致不断的CE,这个时候怎么样来解决的这个问题呢? 很简单,只需要使用inpu...

Python2比较当前图片跟图库哪个图片相似的方法示例

本文实例讲述了Python2比较当前图片跟图库哪个图片相似的方法。分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- ''' Created on 20...