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通过Manager方式实现多个无关联进程共享数据的实现

Python实现多进程间通信的方式有很多种,例如队列,管道等。 但是这些方式只适用于多个进程都是源于同一个父进程的情况。 如果多个进程不是源于同一个父进程,只能用共享内存,信号量等方式,...

详解python调用cmd命令三种方法

目前我使用到的python中执行cmd的方式有三种 使用os.system("cmd")     该方法在调用完shell脚本后,返回一个16位的二进制数...

Python常用的文件及文件路径、目录操作方法汇总介绍

python的文件和路径操作函数基本上位于os和os.path模块中。 os.listdir(dirname):列出dirname下的目录和文件 os.path.isdir(name):...

python 计算方位角实例(根据两点的坐标计算)

知道两点坐标,怎么计算两点方向的方位角? 答:首先计算坐标增量dx,dy(两个对应坐标分量相减,终点的减始点的)。 若dx,dy中有一个为零时,根据另一个的正负决定方位角(0,90,18...

python儿童学游戏编程知识点总结

python爬虫基本告一段落,琢磨搞点其他的,正好在网上看到一个帖子,一个外国13岁小朋友用python写的下棋程序,内容详细,也有意思,拿来练手。 13岁啊。。 我这年纪还在敲 dir...