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中使用requests 模拟浏览器发送请求数据的方法

如下所示: import requests url='http://####' proxy={'http':'http://####:80'} headers={ "Accep...

python Pexpect 实现输密码 scp 拷贝的方法

在服务器A上的程序用到服务器B上的文件data,并且需要定期更新文件。 但是直接在bash文件中使用 scp -P 1000 192.168.199.10:/temp/data /t...

pycharm 取消默认的右击运行unittest的方法

取消默认的右击运行unittest方法: File-> Settings -> Tools -> Python Integrated Tools -> Defau...

解决pycharm回车之后不能换行或不能缩进的问题

解决pycharm回车之后不能换行或不能缩进的问题

如果不小心按到键盘上的Insert键的话,光标显示的就不是一条竖线,而是一个类似方块的阴影区域,比如 插入一下insert键的介绍:它叫插入键,缩写INS。主要用于在文档中切换文本输入...

python通过pil将图片转换成黑白效果的方法

本文实例讲述了python通过pil将图片转换成黑白效果的方法。分享给大家供大家参考。具体分析如下: pil功能强大,convert方法可以轻易的将图片转换,下面的代码可以将图片转换成黑...