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明明pip安装成功却找不到包的问题

如下所示: 原因1:版本不对,如用环境变量设置的python3.7路径,那么用的就是3.7的pip.exe安装了包。却用的是2.7的python运行 原因2:名称重复,在当前路径下有与i...

python中的print()输出

1.普通的输出: print(str)#str是任意一个字符串,数字··· 2.格式化输出: print('1,2,%s,%d'%('asd',4)) 1,2,asd,4 与C语...

安装PyInstaller失败问题解决

安装PyInstaller失败问题解决

这篇文章主要介绍了安装PyInstaller失败问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 pip install P...

Python yield 小结和实例

一个带有 yield 的函数就是一个 generator,它和普通函数不同,生成一个 generator 看起来像函数调用,但不会执行任何函数代码,直到对其调用 next()(在 for...

Python程序员面试题 你必须提前准备!(答案及解析)

Python程序员面试题 你必须提前准备!(答案及解析)

在发布《Python程序员面试,这些问题你必须提前准备!》一文后,应广大程序员朋友的强烈要求,小编就Python程序员面试必备问题整理了一份参考答案,希望能对准备换工作的程序员朋友有所帮...