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

经过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......'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值