自动扫描局域网并且发现指定端口开放的主机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