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 psutil模块简单使用实例

安装很简单 复制代码 代码如下: pip install psutil 官网地址为: https://pythonhosted.org/psutil/ (文档上有详细的api) git...

python使用any判断一个对象是否为空的方法

本文实例讲述了python使用any判断一个对象是否为空的方法。分享给大家供大家参考。 具体实现代码如下: 复制代码 代码如下:>>> eth = {"eth0″:"1...

Python实现定制自动化业务流量报表周报功能【XlsxWriter模块】

Python实现定制自动化业务流量报表周报功能【XlsxWriter模块】

本文实例讲述了Python实现定制自动化业务流量报表周报功能。分享给大家供大家参考,具体如下: 一 点睛 本次实践通过定制网站5个频道的流量报表周报,通过XlsxWriter 模块将流量...

python合并文本文件示例

python实现两个文本合并 employee文件中记录了工号和姓名复制代码 代码如下:cat employee.txt:100 Jason Smith200 John Doe300 S...

vc6编写python扩展的方法分享

系统环境:VC6 + Python-2.5.4 1、下载Python-2.5.4源码。 2、解压,打开D:\Python-2.5.4\PC\VC6\pcbuild.dsw,编译,D:\P...