您的位置:首页 > 运维架构 > Shell

自动扫描局域网并且发现指定端口开放的主机ip的shell脚本

2011-10-18 10:25 786 查看


(原创)自动扫描局域网并且发现指定端口开放的主机ip的shell脚本

博客分类:

linux/windows/unix/bash/shell

脚本XMLBashJ#

经过2天研究,学习shell和awk脚本,得到如下功能:

1。扫描局域网主机的端口开放情况

2。获取指定端口开发的主机ip

3。将获取的ip修改有关配置文件

代码如下,有疑问的可以找我探讨,一起学习!

#!/bin/bash

echo '

Start to delete the old configuration file......'

rm -rf scan_result.xml

rm -rf scan_result_ip.xml

rm -rf scan_result_ip.xml.bak

for ipv in {195..197}

do

echo '

Start to detect the status of port 9035 for host '$ipv'......'

nmap -v 10.0.2.$ipv -p 9035 --append-output -oN scan_result.xml

done

#cho 'Start to find the ip of the host which's 9035 port is open......'

awk 'BEGIN{RS="Interesting ports on bogon"; FS="("; OFS=")"}{for(j=1;j<=NF;j++){if($j~/open/){print $0;break}}}' scan_result.xml > scan_result_ip.xml

echo '

The ip of the host whose 9035 port is open have been found......'

sleep 3

sed 's/(//g' scan_result_ip.xml > scan_result_ip.xml.bak

sed 's/)://g' scan_result_ip.xml.bak > scan_result_ip.xml

head -1 scan_result_ip.xml > scan_result_ip.xml.bak

var=`cat scan_result_ip.xml.bak|sed -e "s/ //g"`

sleep 3

echo '

Start to configure for the edge server......'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: