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实现批量下载文件

Python实现批量下载文件 #!/usr/bin/env python # -*- coding:utf-8 -*- from gevent import monkey monk...

通过Python 接口使用OpenCV的方法

一、在 Anaconda2 中配置 OpenCV 解压 opencv,添加系统环境变量,计算机-->右键属性-->高级系统设置-->环境变量-->系统变量--&g...

django商品分类及商品数据建模实例详解

基类(商品类及分类类之间共同的字段) class BaseModle(models.Model): name = models.CharField(max_length=32,...

Python编程中对文件和存储器的读写示例

1.文件的写入和读取 #!/usr/bin/python # -*- coding: utf-8 -*- # Filename: using_file.py # 文件是创建和读...

python使用jieba实现中文分词去停用词方法示例

前言 jieba 基于Python的中文分词工具,安装使用非常方便,直接pip即可,2/3都可以,功能强悍,十分推荐。 中文分词(Chinese Word Segmentation) 指...