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();

相关文章

Python3 XML 获取雅虎天气的实现方法

参考廖雪峰的Python教程,实现Linux Python3获取雅虎天气 #!/usr/bin/env python3 # coding: utf-8 import os from...

tensorflow: variable的值与variable.read_value()的值区别详解

tensorflow: variable的值与variable.read_value()的值区别详解

问题 查看 tensorflow api manual 时,看到关于 variable.read_value() 的注解如图: 那么在 tensorflow 中,variable的值...

python实现证件照换底功能

本来是在找交通识别的程序,然后凑巧看见了证件照换底,于是学习了一下~一开始在网上找了一个很普遍写的程序,但是效果并不好,想要放弃了,然后看见了这个,参考:python opencv实现证...

Python基于pillow判断图片完整性的方法

本文实例讲述了Python基于pillow判断图片完整性的方法。分享给大家供大家参考,具体如下: 1、安装第三方库。 pip install pillow 2、函数示例。...

分享一个简单的python读写文件脚本

先来看一段创建文件并写入文本的代码,然后作介绍。 #!/usr/bin/env python 'makeFile.py -- create a file'...