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实现的科学计算器功能示例

本文实例讲述了Python实现的科学计算器功能。分享给大家供大家参考,具体如下: import wx import re import math # begin wxGlade: e...

python使用百度文字识别功能方法详解

python使用百度文字识别功能方法详解

介绍python使用百度智能去的文字识别功能,可以识别截图中的文,登陆路验证码等等。, 登陆百度智能云,选择产品服务。 选择“人工智能”---文字识别。 点击创建应用。 如图下面有关...

Python数据分析pandas模块用法实例详解

本文实例讲述了Python数据分析pandas模块用法。分享给大家供大家参考,具体如下: pandas pandas10分钟入门,可以查看官网:10 minutes to pandas...

Python正则表达式匹配数字和小数的方法

Python正则表达式匹配数字和小数的方法

1.正则匹配数字,\为转义字符,d+为匹配一次或多次 如下所示:返回的结果为列表 2.正则匹配小数 如下所示,返回的结果125.6为字符串 总结  以上所述是小编给大家介绍...

Python实现一个带权无回置随机抽选函数的方法

需求 有一个抽奖应用,从所有参与的用户抽出K位中奖用户(K=奖品数量),且要根据每位用户拥有的抽奖码数量作为权重。 如假设有三个用户及他们的权重是: A(1), B(1), C(2)。...