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();

相关文章

Django使用HttpResponse返回图片并显示的方法

做了一个关于Django的小案例,想要在网页中显示图片,直接在img标签的src属性写图片的路径是不能显示的,查询资料发现在Django中使用图片这类的资源相当繁琐需要进行一定D的配置,...

Python3 批量扫描端口的例子

用法 本脚本用于批量扫描端口 1.在同目录下创建输入文件,属性inputFile为输入文件名 2.属性th为线程数 3.属性port为探测的目标端口 4.属性arg为默认的命令 不推荐...

python判断计算机是否有网络连接的实例

先安装第三方库:pip install requests def isConnected(): import requests try: html = request...

selenium设置proxy、headers的方法(phantomjs、Chrome、Firefox)

本文介绍了selenium设置proxy、headers的方法,把phantomjs、Chrome、Firefox几个浏览器的设置方法都总结一下,分享给大家,也给自己留个笔记 phan...

Python3批量生成带logo的二维码方法

最近有个需求:批量生成带Logo的二维码 生成二维码比较简单,网上的资源也比较多,不赘述了。自己研究了一下加了logo并且美化了一下(网上的资源直接加Logo特别丑!!!忍不了!!!),...