当前位置: 移动技术网 > IT编程>脚本编程>Python > python局域网ip扫描示例分享

python局域网ip扫描示例分享

2019年03月31日  | 移动技术网IT编程  | 我要评论

江汉大学商学院,党章网,鬼泣automatic

复制代码 代码如下:

#!/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();

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网