Linux shell????????????????????????
???????????? ???????[ 2016/4/7 11:39:36 ] ?????????????? Linux
????????????????ж?????????????ssh????(???22)???????????????????????????????????????shell?????????????????????????У????????puppet???????????????????????????????????????????????????sed?? awk?? grep???????shell????????
????1?????nmap??????????????????????????????????????nmap1.txt?С?
????1 # ???nmap??????????????????????????????????????nmap1.txt??
????2 mkdir -p /wuhao/sh/files
????3 nmap $1 > /wuhao/sh/files/nmap1.txt
??????nmap 192.168.20.1-10??????????????
Starting Nmap 5.51 ( http://nmap.org ) at 2016-03-03 16:37 CST
Nmap scan report for oos01 (192.168.20.1)
Host is up (0.0000040s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp filtered http
Nmap scan report for oos02 (192.168.20.2)
Host is up (0.000099s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3306/tcp open mysql
MAC Address: 00:1C:42:FF:5A:B5 (Parallels)
Nmap scan report for oos03 (192.168.20.3)
Host is up (0.000097s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3306/tcp open mysql
MAC Address: 00:1C:42:38:94:3C (Parallels)
Nmap done: 10 IP addresses (3 hosts up) scanned in 1.57 seconds
????2???????nmap1.txt???????????????(????ip??????????)??
1 # ?????nmap1.txt???????????????(????ip??????????)
2 sed -n '/(Nmap scan report for|^[0-9]+/)/p' /wuhao/sh/files/nmap1.txt > /wuhao/sh/files/nmap2.txt
3 hosts=($(grep -on '(.*)' /wuhao/sh/files/nmap2.txt | sed -n 's/(|)//gp'))
4 declare -i len=${#hosts[*]}
5 declare -i i=0
6 while [[ $i -lt $len ]]
7 do
8 lines[$i]=$(echo ${hosts[$i]} | awk -F ':' '{print $1}')
9 ips[$i]=$(echo ${hosts[$i]} | awk -F ':' '{print $2}')
10 i=$i+1
11 done
12 # echo ${lines[*]}=1 5 9
13 # echo ${ips[*]}=192.168.20.1 192.168.20.2 192.168.20.3
????3??????????????????????????ip???????????????浽???nmap2.txt?С?
1 # ????????????????????????ip???
2 declare -i j=0
3 while [[ $j -lt $len ]]
4 do
5 declare -i k=$j+1
6 if [ $j -ne $(($len-1)) ]; then
7 sed -i "$((${lines[$j]}+1))??$((${lines[$k]}-1))s/^/${ips[$j]} /" /wuhao/sh/files/nmap2.txt
8 else
9 sed -i "$((${lines[$j]}+1))??$""s/^/${ips[$j]} /" /wuhao/sh/files/nmap2.txt
10 fi
11 j=$j+1
12 done
13
14 # ???????????/?滻???????
15 sed -i 's/ +|// /g' /wuhao/sh/files/nmap2.txt
????nmap2.txt??????????
Nmap scan report for oos01 (192.168.20.1)
192.168.20.1 21 tcp open ftp
192.168.20.1 22 tcp open ssh
192.168.20.1 80 tcp filtered http
Nmap scan report for oos02 (192.168.20.2)
192.168.20.2 22 tcp open ssh
192.168.20.2 80 tcp open http
192.168.20.2 3306 tcp open mysql
Nmap scan report for oos03 (192.168.20.3)
192.168.20.3 22 tcp open ssh
192.168.20.3 80 tcp open http
192.168.20.3 3306 tcp open mysql
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11