#!/bin/bash
#This script name is scan_analyse.sh
. /etc/profile
echo "start time is $(date)"
time=$(date +"%Y-%m-%d")
yesterday=`date -d "1 day ago " +"%Y-%m-%d"`
work_dir="/root/nmap_scan"
now_dir="$work_dir/scan_result/$time"
IP='1.1.1.0/24'
contact_mail='xx@mail.com'
rm -rf $now_dir
if [ ! -d "$work_dir/scan_result/$time" ];then
mkdir -p $work_dir/scan_diff_result/$time
fi
rm -rf $work_dir/scan_diff_result/$time/result.log
ip_32=`echo $IP|cut -d . -f -`
if [ ! -d $now_dir/$ip_32 ];then
mkdir -p $now_dir/$ip_32
fi
for i in {..}
do
nmap -sS -r -n $ip_32.$i |egrep -v "(Starting|scanned)"|egrep "(Nmap|open)" >$now_dir/$ip_32/$ip_32.$i
if [ `cat $now_dir/$ip_32/$ip_32.$i|wc -l` -eq ];then
rm -rf $now_dir/$ip_32/$ip_32.$i
fi
done
echo "stop time is $(date)"
for b in $ip_32
do
for i in $(ls $now_dir/$b)
do
if [ ! -f "$work_dir/scan_source/$b/$i" ];then
echo "增加新主机 $i,下面是全部信息:">>$work_dir/scan_diff_result/$time/result.log
if [ `cat $now_dir/$b/$i|wc -l` -gt ];then
echo "开启了所有端口,怀疑是有nat或者负载均衡!">>$work_dir/scan_diff_result/$time/result.log
else
cat $now_dir/$b/$i>>$work_dir/scan_diff_result/$time/result.log
fi else
if [ `diff -u $now_dir/$b/$i $work_dir/scan_source/$b/$i|egrep -v "(\-\-\-|\+\+\+|@@)"|egrep "(Nmap|\-|\+)"|wc -l` -gt ];then
head -n $now_dir/$b/$i>>$work_dir/scan_diff_result/$time/result.log
echo "开启了所有端口,怀疑是有nat或者负载均衡!">>$work_dir/scan_diff_result/$time/result.log
else
diff -u $now_dir/$b/$i $work_dir/scan_source/$b/$i|egrep -v "(\-\-\-|\+\+\+|@@)"|egrep "(Nmap|\-|\+)"|sed -e 's# Nmap scan report for#扫描主机#g'|sed -e 's#^+#关闭了 #g' -e 's#^-#开启了 #g'>>$work_dir/scan_diff_result/$time/result.log
fi
fi
done
done
if [ `cat $work_dir/scan_diff_result/$time/result.log|wc -l` -eq ];then
echo "今日一切正常,没有变化的端口!"|mail -s "【$time】所有IDC机房差异端口扫描结果" $contact_mail
else
sed -i "1i 大家好: \n 下面是$time日所有IDC机房扫描新增主机或已有主机新增或关闭端口情况,请各项目负责人及时认领与确认.\n" $work_dir/scan_diff_result/$time/result.log
cat $work_dir/scan_diff_result/$time/result.log|mail -s "【$time】所有IDC机房差异端口扫描结果" $contact_mail
fi
rm -rf $work_dir/scan_source/
cp -a $work_dir/scan_result/$time $work_dir/scan_source
if [ $? -eq ];then
echo "运行完成,操作成功!"
else
echo "运行完成,操作失败!"
fi

端口安全检查shell脚本的更多相关文章

  1. 基于nc命令监控服务端口的Shell脚本

    Shell代码: #!/bin/bash export LANG=en_US.UTF- #IP Address=127.0.0.1 #Port Port= #尝试的次数 n= #nc timeout, ...

  2. Linux部署项目 shell脚本启动 及 Centos7开放指定端口

    我们首先要在linux上安装好jdk   tomcat   mysql  这些基本环境,这些可以在楼主的  Linux入门   里面找到. linux部署spring项目 1. 右击项目,maven ...

  3. 如何使用 Shell 脚本来查看多个服务器的端口是否打开?

    我们在进行服务器配置的时候,经常要查看服务器的某个端口是否已经开放.如果服务器只有一两台的话,那很好办,只需要使用 nc 命令一个个查看即可. 但是,如果你的服务器是个集群,有很多台呢?那如果还一个个 ...

  4. 该死的端口占用!教你用 Shell 脚本一键干掉它!

    1. 前言 大家好,我是安果! 在 Web 开发中,经常会遇到「端口被占用」的场景 常规解决方案是: 使用 lsof -i 命令查询占用端口的进程 PID 利用 kill -9 PID 干掉目标进程 ...

  5. shell脚本批量开启防火墙端口

    # 注意:shell脚本批量执行命令,不能只写一个函数,然后把所有命令复制进去,之前试过这样是不行的.必须要有一个判断命令执行成功与否的语句 # 简单的命令可以不加结果判断符号,但是遇到解压包.sed ...

  6. linux下shell脚本执行jar文件

    最近在搞一个shell脚本启动jar文件个关闭jar文件的东东.搞得我都蛋疼了.今天晚上终于弄好了 话说,小弟的linux只是刚入门,经过各方查资料终于搞定了.话不多说,下面开始上小弟写的shell脚 ...

  7. Linux常用命令及shell脚本

    一.     用户管理(添加用户.切换用户.删除用户) ~                                                                        ...

  8. CentOS 下运维自动化 Shell 脚本之 expect

    CentOS 下运维自动化 Shell脚本之expect 一.预备知识: 1.在 Terminal 中反斜杠,即 "" 代表转义符,或称逃脱符.("echo -e与pri ...

  9. 【转】常用的shell脚本

    from:http://blog.sina.com.cn/s/blog_4152a9f501013r6c.html 常用的shell脚本 (2012-10-10 22:09:07) 转载▼ 标签: 杂 ...

随机推荐

  1. mybatis-spring-1.2.1 jar下载、源码下载

    http://www.everycoding.com/maven2/org/mybatis/mybatis-spring/1.2.1.html

  2. Android ImageResizer:inSampleSize

    import android.annotation.TargetApi; import android.content.Context; import android.content.res.Reso ...

  3. sencha touch 入门系列 (九)sencha touch 视图组件简介

    对于一个普通用户来说,你的项目就是一组简单的视图集合,用户直接通过跟视图进行交互来操作你的应用,对于一个开发人员来说,视图是一个项目的入口,虽然大部分时候最有价值的部分是在model层和control ...

  4. 1.执行环境判断 window 或 self

    window or self ? 在 underscore 的判断所处环境的代码中,似乎我们没有看到 window 对象的引用,其实,在浏览器环境下,self 保存的就是当前 window 对象的引用 ...

  5. 基于TINY4412的Andorid开发-------简单的LED灯控制

    参考资料: <Andriod系统源代码情景分析> <嵌入式Linux系统开发完全手册_基于4412_上册> 作者:彭东林 邮箱:pengdonglin137@163.com 平 ...

  6. 【BZOJ1030】[JSOI2007]文本生成器 AC自动机+动态规划

    [BZOJ1030][JSOI2007]文本生成器 Description JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文 ...

  7. Unity3D笔记七 GUILayout

    一.说到GUILayout就要提到GUI,二者的区别是什么 GUILayout是游戏界面的布局.GUI(界面)和GUILayout(界面布局)功能上面是相似的从命名中就可以看到这两个东西非常相像,但是 ...

  8. java后端技术栈

  9. 强连通分量+缩点(poj2553)

    http://poj.org/problem?id=2553 The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total ...

  10. Mybatis框架插件PageHelper的使用

    在web开发过程中涉及到表格时,例如dataTable,就会产生分页的需求,通常我们将分页方式分为两种:前端分页和后端分页. 前端分页 一次性请求数据表格中的所有记录(ajax),然后在前端缓存并且计 ...