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正则分组的应用

复制代码 代码如下:import retext='V101_renow.Android.2.2.Normal.1.Alpha.apk?IMSI=460029353813976&MOBIL...

Python with用法实例

python中with可以明显改进代码友好度,比如: 复制代码 代码如下: with open('a.txt') as f:      prin...

Python脚本实现自动将数据库备份到 Dropbox

最近,正好发生了一件大事,就是 GitLab 的运维同学不小心删除了生产的数据,虽然 GitLab 已经骇人听闻的准备了五种备份机制,但是,仍然导致他们丢失了将近 6 个小时的用户数据,...

python创建n行m列数组示例

我就废话不多说了,直接上代码吧! >>> matrix=[None]*2 >>> print(matrix) [None, None] >&...

Tensorflow获取张量Tensor的具体维数实例

获取Tensor的维数 >>> import tensorflow as tf >>> tf.__version__ '1.2.0-rc1'...