The following is an example of Telnet to port 22
Station91:~/shell/telnet_port # pwd
/root/shell/telnet_port
Station91:~/shell/telnet_port # Cat Telnet_port.sh
#!/bin/bash
RM telnet_result.txt >/dev/null 2>&1
Port_22=22
For I in $ (cat ip.list)
Do (telnet $i $PORT _22< >telnet_result.txt &) >/dev/null 2>&1
#加 & Let it execute in parallel, >>telnet_result.txt logs during Telnet
Quit
Eof
Done
Cat Telnet_result.txt | Grep-b 1] | grep [1-9] | awk ' {print $} ' | Cut-d '. '-F 1,2,3,4 > Telnet_alive.txt
Cat Ip.list Telnet_alive.txt | Sort | Uniq-u > Telnet_die.txt
Station91:~/shell/telnet_port # for I in {88..93};d o echo "192.168.14. $i" >>ip.list;done #使用for循环得到需要telnet主机的ip
Station91:~/shell/telnet_port # Cat Ip.list
192.168.14.88
192.168.14.89
192.168.14.90
192.168.14.91
192.168.14.92
192.168.14.93
Station91:~/shell/telnet_port # ls
Ip.list telnet_port.sh
Station91:~/shell/telnet_port #./telnet_port.sh &
[1] 16848
Station91:~/shell/telnet_port # ls
Ip.list telnet_alive.txt telnet_die.txt telnet_port.sh telnet_result.txt
[1]+ done./telnet_port.sh
Station91:~/shell/telnet_port # Cat Telnet_alive.txt//from native Telnet to port 22 port can telnet through only 192.168.14.91
192.168.14.91
Station91:~/shell/telnet_port # Cat Telnet_die.txt
192.168.14.88
192.168.14.89
192.168.14.90
192.168.14.92
192.168.14.93
Station91:~/shell/telnet_port # Cat Telnet_result.txt//logging log format
Trying 192.168.14.91 ...
Connected to 192.168.14.91.
Escape character is ' ^] '.
Trying 192.168.14.88 ...
Trying 192.168.14.89 ...
Trying 192.168.14.90 ...
Trying 192.168.14.92 ...
Trying 192.168.14.93 ...