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实现对PPT文件进行截图操作的方法

本文实例讲述了Python实现对PPT文件进行截图操作的方法。分享给大家供大家参考。具体分析如下: 下面的代码可以为powerpoint文件ppt进行截图,可以指定要截取的幻灯片页面,需...

Python3 安装PyQt5及exe打包图文教程

Python3 安装PyQt5及exe打包图文教程

环境: Python 3.6.4 + Pycharm Professional 2017.3.3 + PyQt5 + PyQt5-tools ① Python 3 安装 Python 3...

python绘制多个曲线的折线图

python绘制多个曲线的折线图

这篇文章利用的是matplotlib.pyplot.plot的工具来绘制折线图,这里先给出一个段代码和结果图: # -*- coding: UTF-8 -*- import nump...

Python常见排序操作示例【字典、列表、指定元素等】

本文实例讲述了Python常见排序操作。分享给大家供大家参考,具体如下: 字典排序 按value排序 d1 = {"name":"python","bank":"icbc",...

如何基于python实现脚本加密

如何基于python实现脚本加密

这篇文章主要介绍了如何基于python实现脚本加密,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 from pathlib im...