地址: http://blog.csdn.net/hujkay

作者:Jekkay Hu(34538980@qq.com)

关键词:主机扫描,主机存活,纯python版本,非nmap

时间: 2014/1/21

最近受好友所托写个python脚本,就是扫描局域网的主机存活的情况,这个在内网渗透时非常有用,因为你在跳板机上贸然安装namp等扫描工具,则很容易被发现,我抽时间写了个python脚本,使用ping工具来监测主机存活情况。我写的这个脚本时采用单线程的方式工作,所效率不是很快,下个版本我在优化成多线程的版本,同时也让支持扫描端口等功能。

#!/usr/bin/env python
#-*- coding: utf8 -*-
#
# Author: Jekkay Hu
# Date: 2014/1/21
# Email: jekkay@gmail.com
# QQ: 34538980
#import os
import sys# Convert IP Format:  Number['3232247553] <----> String ['192.168.47.1']
IPNumToString = lambda x: '.'.join([str(x/(256**i)%256) for i in range(3,-1,-1)])
IPStringToNum = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[::-1])])
# start IP -- End IP
StartIP = 0
EndIP = 0def welcome():welcomeinfo = """
======================================================
=                                                    =
=                    scanhost V1.0                   =
=           Jekkay Hu,  Written in 2014/1/21         =
=           34538980@qq.com, Jekkay@gmail.com        =
= More please visit: http://blog.csdn.net/hujkay     =
=                                                    =
======================================================
"""print welcomeinfodef help():helpinfo = """
======================================================
=                                                    =
=                    scanhost V1.0                   =
=           Jekkay Hu,  Written in 2014/1/21         =
=           34538980@qq.com, Jekkay@gmail.com        =
= More please visit: http://blog.csdn.net/hujkay     =
=                                                    =
=  Usage:                                            =
=    python scanhost.py 1.2.3.4                      =
=    python scanhost.py 1.2.3.4-255                  =
=    python scanhost.py 1.2.3.4 - 1.2.4.5            =
======================================================
"""print helpinfodef parseargs():try:commandargs = sys.argv[1:]if not commandargs:return Falsecommandargs = ''.join(commandargs)commandargs = commandargs.split('-')global StartIPglobal EndIPcommandlen = len(commandargs)if commandlen == 1:StartIP = EndIP = int(IPStringToNum(commandargs[0]))elif commandlen == 2:StartIP = commandargs[0]EndIP = commandargs[1]if len(StartIP.split('.')) !=4 :return Falseendiplen =  len(EndIP.split('.'))if endiplen == 1:prefixip = StartIP.split('.')[0:3]prefixip.append(EndIP)EndIP = '.'.join(prefixip)elif endiplen == 4:passelse:return False#print "startip",StartIP,",endip:",EndIPStartIP = int(IPStringToNum(StartIP))EndIP   = int(IPStringToNum(EndIP))except Exception,e:# any exception occursprint ereturn Falsereturn Truedef checkhoston(ip):try:cmd = ['ping','%s' % IPNumToString(ip),'-c','1']output = os.popen(' '.join(cmd)).readlines()for line in list(output):if not line:continueif str(line).find('ttl') >= 0 or str(line).find('TTL') >= 0:return Trueexcept:passdef processcheckhost(): global StartIPglobal EndIPalivecount = 0StartIP = int(StartIP)EndIP = int(EndIP)totalip = EndIP - StartIP + 1if totalip <= 0:help()exit(0)print 'Startint scan ',IPNumToString(StartIP),' -> ',IPNumToString(EndIP), ',please wait...'fd = open('scanhost.txt',"w")#for i in xrange(StartIP,EndIP+1,1):ip = StartIPwhile True:if ip > EndIP:break if checkhoston(ip):fd.write(IPNumToString(ip))alivecount = alivecount + 1#print IPNumToString(ip)ip = ip + 1sys.stdout.write('#')if (ip-StartIP) % 20 == 0:sys.stdout.write('\r\n')fd.close()return alivecountdef showresult(shownum):fd = open('scanhost.txt',"r")for line in fd.readlines(shownum):print linefd.close()def main():if not parseargs():help()exit(0)welcome()alivecount = processcheckhost()print "\r\n [%d] host is on,please see the scanhost.txt, top 300 will be shown below" % alivecountshowresult(300)if alivecount > 300:print "More ips please see scanhost.txt"if __name__ == '__main__':main()

胡杨, Jekkay Hu

2014/1/21

[批量主机存活扫描工具scanhost]扫描主机存活[python版本,非nmap版本]相关推荐

  1. java 静态扫描_静态代码扫描工具 – (八)- 扫描Java项目

    静态代码扫描工具 – (八)- 扫描Java项目 1.准备好Java项目代码 只要是java语言实现的项目均可. 比如,自动化测试的代码,测试平台等均可以. 本次案例,使用java语言实现的测试平台来 ...

  2. 国产源代码扫描工具DMSCA扫描出的报告优秀吗?

    在源代码扫描工具中,扫描报告是非常具有参考意义的,一方面可以了解我们开发项目的漏洞情况,另一方面也可以针对扫出的漏洞进行修复,确保开发出安全可靠的软件.误报和漏报是一个非常重要的参考指标. 国产源代码 ...

  3. arp扫描工具_ARP扫描与ARP欺骗--Python的Scapy/Kamene模块学习之路

  4. NetBIOS主机名扫描工具nbtscan

    2019独角兽企业重金招聘Python工程师标准>>> NetBIOS主机名扫描工具nbtscan NetBIOS主机名是NetBIOS协议为主机分配的名称.通过NetBIOS主机名 ...

  5. 主机扫描、端口扫描、系统扫描、漏洞扫描

    主机扫描.端口扫描.系统扫描.漏洞扫描 主机扫描 找出网段内活跃主机. 主机扫描方式: 1.传统 ICMP Ping 扫描 2.ACK Ping 扫描 3.SYN Ping 扫描 4.UDP Ping ...

  6. kali linux samba,Kali Linux 渗透测试:SMB、SMTP扫描工具(14)

    一.SMB扫描工具 SMB(Server Message Block)协议,服务消息块协议. 最开始是用于微软的一种消息传输协议,因为颇受欢迎,现在已经成为跨平台的一种消息传输协议. 同时也是微软历史 ...

  7. Web安全:安全扫描工具

    安全扫描工具可以分为系统扫描工具与应用扫描工具.安全扫描工具可以很好地发现网络空间中主机或者应用的安全漏洞.因此,借助于安全扫描工具,我们可以更好地对网络空间中的主机或者应用的安全漏洞进行漏洞处置,从 ...

  8. 自动化漏洞扫描工具使用指南

    作为企业的IT安全管理员,您的重要任务之一,一定离不开全面的漏洞管理.即,全方位地评估.报告和缓解企业内部技术栈中,存在的各项安全弱点和网络威胁.而面对此类繁杂复杂的工作时,我们往往需要借助自动化的漏 ...

  9. A Taxonomy for Contrasting Industrial Control Systems Asset Discovery Tools(对工业控制系统资产扫描工具的分类比较)

    论文原文:A Taxonomy for Contrasting Industrial Control Systems Asset Discovery Tools 原文作者:E Samanis,J Ga ...

最新文章

  1. 大道至简:算法工程师炼丹Trick手册
  2. 18000 台服务器整整瘫痪了三天:因 BoltDB 糟糕的设计
  3. Activity的setResult方法
  4. elementui图片上传php,vue+Element Ui 实现自动上传图片
  5. 使用Docker for Windows初体验
  6. 功能接口简介–在Java 8中重新创建的概念
  7. Java GregorianCalendar getTimeZone()方法与示例
  8. jenkins解决jenkins内存溢出问题
  9. php tls,使用TLS在PHP中建立连接
  10. 多线程的那点儿事(基础篇)
  11. 用python二重循环求成绩表_python的循环
  12. MiniGUI编程--编辑框
  13. Halcon基本例程(二)
  14. 计算机电路基础实验一仪器使用,计算机电路基础(1)实验.pdf
  15. 引路蜂地图API:Gis.Location包定义
  16. HUSTOJ(2019)在线判题系统的从零开始搭建过程
  17. 如何查看对方的QQ登录是IP地址的方法
  18. 《回炉重造》——Lambda表达式
  19. 京东登录注册页面的简单实现——(仿)
  20. Windows下安装VScode,并使用,以及中文配置

热门文章

  1. Linux学习-Boot Loader: Grub2
  2. Android自定义适配器
  3. .NET c#音乐播放器
  4. 谷歌浏览器下载的内容老是自动打开
  5. [React Error]: Target container is not a DOM element
  6. solaris服务器系统,Sun Solaris系统服务器RAID-5数据恢复实例分析
  7. 输入【ionic start myApp tabs】命令创建项目时失败
  8. 程序员代码对比工具,就用这7个
  9. TI-RTOS实时操作系统开发之低速时钟32.768kHz晶振检测
  10. MT6(8)735平台Android5.1 codege.dws 文件