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 获得任意路径下的文件及其根目录的方法

似乎有一段时间没有更新博客了,这里就写点小功能,轻松获得电脑任意路径下的文件及文件夹,并将其写入word,以下是主要代码: **import os** **from os impor...

Matplotlib绘制雷达图和三维图的示例代码

Matplotlib绘制雷达图和三维图的示例代码

1.雷达图 程序示例 '''1.空白极坐标图''' import matplotlib.pyplot as plt plt.polar() plt.show()...

python实现简易云音乐播放器

本人最近在学习python,在看了一些教程后,用python写了一个简单的云音乐播放器,下面把主要代码贴上来,其中用到了github上他人写的一个汉字转拼音的库,大家可以在github上...

Python常用模块sys,os,time,random功能与用法实例分析

Python常用模块sys,os,time,random功能与用法实例分析

本文实例讲述了Python常用模块sys,os,time,random功能与用法。分享给大家供大家参考,具体如下: sys: 介绍:主要包含涉及python编译器与系统交互的函数。 常用...

初步认识Python中的列表与位运算符

初步认识Python中的列表与位运算符

Python列表 List(列表) 是 Python 中使用最频繁的数据类型。 列表可以完成大多数集合类的数据结构实现。它支持字符,数字,字符串甚至可以包含列表(所谓嵌套)。 列表用[...