linux服务器扫描,linux服务器批量扫描文件中IP信息

适用于从服务器的应用目录扫描含有ip信息文件,目录可以通过参数指定,也可以不指定,若不指定则自行根据容器类型扫描对应目录下的文件,示例如下:

6245d11df8a6?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

示例1.PNG

6245d11df8a6?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

示例2.PNG

6245d11df8a6?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

示例3.PNG

6245d11df8a6?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

示例4.PNG

代码如下:

#!/bin/sh

#定义数组

declare -a filename

declare -a contentinfo

#获取本机ip

host=`hostname -i`

#获取进程信息,界定容器类型

ins_tomcat=`ps -ef|grep -v 'grep'|grep "\-Dcatalina.base"|wc -l`

ins_was=`ps -ef|grep -v 'grep'|grep "nodeagent"|wc -l`

ins_weblogic=`ps -ef|grep -v 'grep'|grep "Dweblogic.Name"|wc -l`

ins_nginx=`ps -ef|grep "nginx"|grep -v 'grep'|grep "master process"|wc -l`

IFS='

'

#确定应用目录

if [ $# -gt 0 ];then

thepath=$1

else

if [ $ins_tomcat -gt 0 ];then

thepath=`ps -ef|grep "\-Dcatalina.base"|grep -v 'grep'|awk -F "-Dcatalina.base=" '{print $2}'|grep -v 'print'|awk '{print $1}'`

elif [ $ins_was -gt 0 ];then

thepath=`ps -ef|grep "nodeagent"|grep -v 'grep'|awk -F 'Dwas.install.root=' '{print $2}'|awk '{print $1}'`

elif [ $ins_weblogic -gt 0 ];then

thepath=`cat /wls/serveradmin/conf/env/*.env|grep "APP_HOME"|head -1|awk -F '=' '{print $2}'`

elif [ $ins_nginx -gt 0 ];then

thepid=`ps -ef|grep "nginx"|grep "master process"|grep -v 'grep'|awk '{print $2}'`

thepath=`lsof|grep $thepid|grep 'txt'|awk '{print $9}'|awk -F '/sbin' '{print $1}'`

else

echo '[ERROR] 获取路径失败,请检查!'

fi

fi

#获取待扫描目标文件列表

files=`find $thepath -type f ! -name "*.log" -a ! -name "*.jar" -a ! -name "*.bak" -a ! -name "*.bak*" -a ! -name "*.gz" -a ! -name "*.log*" -a ! -name "*.out" -a ! -name "*.class" -print 2>/dev/null`

#扫描ip地址

for file in $files

do

elfcheck=`readelf -h $file 2>/dev/null`

filetypecheck=`file -b $file|awk '{print $1}'`

if [ -z "$elfcheck" -o "$filetypecheck" != "ELF" ];then

findinfo=`grep -n -o '[1-9][0-9]\{0,2\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' $file 2>/dev/null|uniq`

if [ -n "${findinfo}" ];then

filename=(${filename[*]} $file)

contentinfo=$contentinfo"文件"$file"\n第"$findinfo"\n"

((number++))

fi

else

echo "[INFO] "$file"是编译后的ELF文件,跳过扫描."

fi

done

wait

#结果展示

filecount=${#filename[@]}

echo "*********************************************************************"

if [ $filecount -gt 0 ];then

echo "[INFO] 主机$host共有如下$filecount个文件存在符合条件的ip:"

for ii in ${filename[@]}

do

echo " ${ii}"

done

echo "[INFO] ip分布情况如下:"

echo "-----------------------------------------------------"

for theinfo in $contentinfo;do

echo -e "第"${theinfo//:/行存在ip:}

done

echo "-----------------------------------------------------"

else

echo "[INFO] 主机$host没有文件存在符合条件的ip"

fi

echo "*********************************************************************"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值