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基础入门学习笔记(Python环境搭建)

python基础入门学习笔记(Python环境搭建)

Python学习第一篇。把之前学习的Python基础知识总结一下。 一、认识Python 首先我们得清楚这个:Python这个名字是从Monty Python借鉴过来的,而不是源于大家所...

Python处理PDF及生成多层PDF实例代码

Python提供了众多的PDF支持库,本文是在Python3环境下,试用了两个库来完成PDF的生成的功能。PyPDF对于读取PDF支持较好,但是没找到生成多层PDF的方法。Reportl...

简洁的十分钟Python入门教程

【简介】 Python是一种动态解释型的编程语言。Python可以在Windows、UNIX、MAC等多种操作系统上使用,也可以在Java、.NET开发平台上使用。 【特点】 1 Pyt...

Python3多目标赋值及共享引用注意事项

Python中多目标赋值即将等号左边所有的变量名都赋值给右边的对象,完成赋值操作,比如将三个变量同时赋值给一个字符串。 a = b = c = 'Python' print(a) p...

对python的输出和输出格式详解

对python的输出和输出格式详解

输出 1. 普通的输出 # 打印提示 print('hello world') 用print()在括号中加上字符串,就可以向屏幕上输出指定的文字。比如输出'hello, world...