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自动化测试之如何解析excel文件

前言 自动化测试中我们存放数据无非是使用文件或者数据库,那么文件可以是csv,xlsx,xml,甚至是txt文件,通常excel文件往往是我们的首选,无论是编写测试用例还是存放测试数据,...

python实现异步回调机制代码分享

1 将下面代码拷贝到一个文件,命名为asyncore.py 复制代码 代码如下:import socketimport selectimport sys def ds_asyncore(...

Pandas之ReIndex重新索引的实现

约定: import pandas as pd import numpy as np ReIndex重新索引 reindex()是pandas对象的一个重要方法,其作用是创建一...

Python图像处理之图像的缩放、旋转与翻转实现方法示例

Python图像处理之图像的缩放、旋转与翻转实现方法示例

本文实例讲述了Python图像处理之图像的缩放、旋转与翻转实现方法。分享给大家供大家参考,具体如下: 图像的几何变换,如缩放、旋转和翻转等,在图像处理中扮演着重要的角色,python中的...

python实现统计代码行数的方法

本文实例讲述了python实现统计代码行数的方法。分享给大家供大家参考。具体实现方法如下: ''' Author: liupengfei Function: count lines...