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

相关文章

pymysql模块的操作实例

pymysql 模块! pymysql模块时一个第三方模块!需要下载: pymysql的基本使用: import pymysql conn = pymysql.connect(...

Python基础知识点 初识Python.md

Python基础知识点 初识Python.md

Python简介 Python的历史 1989年圣诞节:Guido von Rossum开始写Python语言的编译器。 1991年2月:第一个Python编译器(同时也是解释器)...

python实现网站用户名密码自动登录功能

一、概述 公司需要通过网页用户认证登录实现上网,网络设备判断当前帐号12小时没有没上网将会自动断开帐号上网,每天早上上班第一件事就是打开用户认证网页输入。 用户名与密码,有时候要家里通过...

Python编写屏幕截图程序方法

正在编写的程序用的很多Windows下的操作,查了很多资料。看到剪切板的操作时,想起以前想要做的一个小程序,当时也没做,现在正好顺手写完。 功能:按printscreen键进行截图的时候...

Python中尝试多线程编程的一个简明例子

Python中尝试多线程编程的一个简明例子

综述     多线程是程序设计中的一个重要方面,尤其是在服务器Deamon程序方面。无论何种系统,线程调度的开销都比传统的进程要快得多。   Py...