当前位置: 首页 > news >正文

shell脚本案例(五)利用nmap批量扫描存活主机

利用nmap批量扫描存活主机

知识储备:grep,nmap

一、安装nmap

1.安装编译环境

[root@arppinging nmap-7.01]# yum install gcc g++ gcc-c++ -y

2.使用wget下载nmap

[root@arppinging nmap-7.01]# wget http://nmap.org/dist/nmap-7.01.tar.bz2

3.解压下载的安装包

[root@arppinging nmap-7.01]# tar -vxf nmap-7.01.tar.bz2 

4.进入文件夹编译安装

[root@arppinging nmap-7.01]# cd nmap-7.01
[root@arppinging nmap-7.01]# ./configure 
[root@arppinging nmap-7.01]# make
[root@arppinging nmap-7.01]# make install

5.检查安装是否成功

[root@arppinging nmap-7.01]# nmap -v

使用nmap

1.sn参数
-sn: Ping Scan - disable port scan #ping探测扫描主机, 不进行端口扫描
2.扫描不存在的主机

Starting Nmap 7.01 ( https://nmap.org ) at 2018-05-24 00:30 CST
Warning: File ./nmap-payloads exists, but Nmap is using /usr/local/bin/../share/nmap/nmap-payloads for security and consistency reasons.  set NMAPDIR=. to give priority to files in your local directory (may affect the other data files too).
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 0.49 seconds
[root@arppinging nmap-7.01]# 

3.扫描存在的主机

[root@arppinging nmap-7.01]# nmap -sn 172.25.65.100
.
Starting Nmap 7.01 ( https://nmap.org ) at 2018-05-24 00:31 CST
Warning: File ./nmap-payloads exists, but Nmap is using /usr/local/bin/../share/nmap/nmap-payloads for security and consistency reasons.  set NMAPDIR=. to give priority to files in your local directory (may affect the other data files too).
Stats: 0:00:00 elapsed; 0 hosts completed (0 up), 1 undergoing ARP Ping Scan
ARP Ping Scan Timing: About 100.00% done; ETC: 00:31 (0:00:00 remaining)
Nmap scan report for 172.25.65.100
Host is up (0.00025s latency).
MAC Address: 2C:FD:A1:E1:EA:DB (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.17 seconds

对比发现,存在的主机都有Nmap scan report for字段

创建脚本

1.脚本如下

[root@arppinging scripts]# cat host.sh 
#/bin/bash -
read -p "Please input scan host or network:" host
nmap -sn $host | grep "Nmap scan report for" >/dev/null &>/dev/null
[ $? -ne 0 ] && echo "host $host is down." && exit 1
nmap -sn $host  | grep "Nmap scan report for" | awk '{print $5}' > /scripts/host.txt
while read uphost
do
 echo "host $uphost is up."
done</scripts/host.txt
[root@arppinging scripts]# 

2.运行脚本(真实环境下)

[root@localhost scripts]# bash host.sh
Please input scan host or network:172.25.65.0/24
host 172.25.65.1 is up.
host 172.25.65.2 is up.
host 172.25.65.50 is up.
host 172.25.65.100 is up.
host 172.25.65.101 is up.
host 172.25.65.102 is up.
host 172.25.65.103 is up.
host 172.25.65.104 is up.
host 172.25.65.105 is up.
host 172.25.65.106 is up.
host 172.25.65.107 is up.
host 172.25.65.108 is up.
host 172.25.65.109 is up.
host 172.25.65.110 is up.
host 172.25.65.111 is up.
host 172.25.65.112 is up.
host 172.25.65.113 is up.
host 172.25.65.114 is up.
host 172.25.65.115 is up.
host 172.25.65.116 is up.
host 172.25.65.117 is up.
host 172.25.65.118 is up.
host 172.25.65.119 is up.
host 172.25.65.120 is up.
host 172.25.65.121 is up.
host 172.25.65.122 is up.
host 172.25.65.123 is up.
host 172.25.65.124 is up.
host 172.25.65.125 is up.
host 172.25.65.126 is up.
host 172.25.65.127 is up.
host 172.25.65.128 is up.
host 172.25.65.129 is up.
host 172.25.65.130 is up.
host 172.25.65.131 is up.
host 172.25.65.132 is up.
host 172.25.65.133 is up.
host 172.25.65.134 is up.
host 172.25.65.135 is up.
host 172.25.65.136 is up.
host 172.25.65.137 is up.
host 172.25.65.138 is up.
host 172.25.65.139 is up.
host 172.25.65.141 is up.
host 172.25.65.143 is up.
host 172.25.65.145 is up.
host 172.25.65.146 is up.
host 172.25.65.147 is up.
host 172.25.65.148 is up.
host 172.25.65.149 is up.
host 172.25.65.150 is up.
host 172.25.65.151 is up.
host 172.25.65.152 is up.
host 172.25.65.10 is up.

主机不存在的情况
[root@localhost scripts]# bash host.sh
Please input scan host or network:172.25.65.199
host 172.25.65.199 is down.
[root@localhost scripts]# 

有问题的话请评论吧,谢谢

arppinging技术社区
欢迎关注的我的个人微信公众号

二维码

转载于:https://blog.51cto.com/xiaowangzai/2119515

相关文章:

  • Echarts关于仪表盘
  • mysql 查询当天、本周,本月,上一个月的数据---https://www.cnblogs.com/benefitworld/p/5832897.html...
  • php实现求数组中出现次数超过一半的数字(isset($arr[$val]))(取不同数看剩)(排序取中)...
  • linux---文件颜色含义
  • echarts学习笔记 各图配置(折线图、圆环图、柱形图、折线面积图)
  • 如何查看一个网页特定效果的js代码(动画效果可js和css)(页面可以看到js的源代码)...
  • (转)创业的注意事项
  • Retrofit 用Soap协议访问WebService 详解
  • kunbernetes存储系统-基于NFS的PV服务
  • 使用TensorFlow高级别的API进行编程
  • Java知识点总结(Java容器-Vector)
  • mybatis返回部分字段为空的问题
  • Confluence 6 SQL Server 数据库驱动修改
  • Python常见问题系列
  • ES6系列(二)变量的解构赋值
  • [译] React v16.8: 含有Hooks的版本
  • Git 使用集
  • JavaScript设计模式与开发实践系列之策略模式
  • Java新版本的开发已正式进入轨道,版本号18.3
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • nodejs:开发并发布一个nodejs包
  • orm2 中文文档 3.1 模型属性
  • PHP 的 SAPI 是个什么东西
  • SpringCloud(第 039 篇)链接Mysql数据库,通过JpaRepository编写数据库访问
  • 编写高质量JavaScript代码之并发
  • 从重复到重用
  • 第十八天-企业应用架构模式-基本模式
  • 分享一个自己写的基于canvas的原生js图片爆炸插件
  • 深度学习中的信息论知识详解
  • 时间复杂度与空间复杂度分析
  • 使用agvtool更改app version/build
  • 数组的操作
  • 项目管理碎碎念系列之一:干系人管理
  • Spring第一个helloWorld
  • 长三角G60科创走廊智能驾驶产业联盟揭牌成立,近80家企业助力智能驾驶行业发展 ...
  • ## 临床数据 两两比较 加显著性boxplot加显著性
  • #HarmonyOS:Web组件的使用
  • #Linux(Source Insight安装及工程建立)
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • (01)ORB-SLAM2源码无死角解析-(56) 闭环线程→计算Sim3:理论推导(1)求解s,t
  • (java版)排序算法----【冒泡,选择,插入,希尔,快速排序,归并排序,基数排序】超详细~~
  • (Pytorch框架)神经网络输出维度调试,做出我们自己的网络来!!(详细教程~)
  • (附源码)springboot家庭装修管理系统 毕业设计 613205
  • (三)mysql_MYSQL(三)
  • (十)【Jmeter】线程(Threads(Users))之jp@gc - Stepping Thread Group (deprecated)
  • (十五)使用Nexus创建Maven私服
  • .bat批处理(五):遍历指定目录下资源文件并更新
  • .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划
  • .NET 跨平台图形库 SkiaSharp 基础应用
  • .net 写了一个支持重试、熔断和超时策略的 HttpClient 实例池
  • .net解析传过来的xml_DOM4J解析XML文件
  • .NET开发不可不知、不可不用的辅助类(一)
  • .NET值类型变量“活”在哪?
  • @EventListener注解使用说明
  • @transactional 方法执行完再commit_当@Transactional遇到@CacheEvict,你的代码是不是有bug!...