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

相关文章

对python3中pathlib库的Path类的使用详解

对python3中pathlib库的Path类的使用详解

用了很久的os.path,今天发现竟然还有这么好用的库,记录下来以便使用。 1.调用库 from pathlib import 2.创建Path对象 p = Path('D:...

Python实现某论坛自动签到功能

1.[文件] DakeleSign.py ~ 4KB #!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'popp...

浅谈Python采集网页时正则表达式匹配换行符的问题

如下所示: p1 = r'(?<=<div class="ds_cr">)(.*?)(?=<div id="pageurl">)...

Python3.5 Pandas模块之Series用法实例分析

Python3.5 Pandas模块之Series用法实例分析

本文实例讲述了Python3.5 Pandas模块之Series用法。分享给大家供大家参考,具体如下: 1、Pandas模块引入与基本数据结构 2、Series的创建...

python 列表递归求和、计数、求最大元素的实例

利用python的递归来执行求和、计数、求最大元素的方法简直溜到爆,这里粘贴一下代码: 列表的递归求和: def sum(list): if list==[]: return...