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中的float除法和整除法的实例详解

从python2.2开始,便有两种除法运算符:"/"、"//"。两者最大区别在: python2.2前的版本和python2.2以后3.0以前的版本的默认情况下,"/"所做的除法是以一种...

将python依赖包打包成window下可执行文件bat方式

1、 打开一个记事本,将需要安装的第三方python依赖包写入文件,比如:需要安装urllib3、flask、bs4三个python库(替换成你想要安装的库,每个库之间用空格隔开),输入...

python得到qq句柄,并显示在前台的方法

如下所示: # 导入模块 import win32gui win = win32gui.FindWindow(None, u'张三') # 将窗口调到前台 win32gui.Show...

python retrying模块的使用方法详解

前言 我们在写爬虫的过程中,经常遇到爬取失败的情况,这个时候我们一般会通过try块去进行重试,但是每次都写那么一堆try块,真的是太麻烦,所以今天就来说一个比较pythonic的模块,r...

Python中低维数组填充高维数组的实现

Python中低维数组填充高维数组的实现

今天遇到这样一种业务情况: 我的图片的画布是(4,4,3)的三维数组,而得到的图片是(2,2,3)的三维数组,我要把图片放到画布的中间某个位置应该怎么做呢? 大家首先想到是遍历循环,但是...