批量检测端口连通性
source link: https://blog.kelu.org/tech/2022/09/14/batch-telnet-ports.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
最简单的办法当然还是使用ansible。
不过客户的一些生产环境没有使用ansible,就写了个简单的脚本测试了下。
- 开头取了
eth0
这个网卡的IP地址。 - 在同一个目录下保存
ip_info
这个文件,每行填写ip:port
#!/bin/bash
LOCALIP=`ifconfig -a | grep eth0 -A 2|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
check_telnet(){
for ip_port in $(cat ./ip_info|grep -v '^#')
do
CHECK_PORT=$(echo $ip_port|awk -F: '{print $2}')
CHECK_IP=$(echo $ip_port|awk -F: '{print $1}')
echo -e "\n"| telnet $CHECK_IP $CHECK_PORT |grep "Connected to\|Escape character" > /dev/null
if [ $? -eq 0 ];then
echo -e "$CHECK_IP\t $CHECK_PORT\t ok"
else
echo -e "$CHECK_IP\t $CHECK_PORT\t error!!!"
fi
done
}
check_telnet > result.log
echo "=========$LOCALIP============="
cat result.log
如果本文对你有帮助,欢迎投食
Recommend
-
40
为了弥补ping的特点,我们通常将ping和telnet一起来使用,既可以通过ping检查网络连通性,也可以通过telnet指定端口。那么,除了它们,还有哪些工具可以用来测试端口连通性呢?这里给大家分享一下其他的工具。
-
62
为了弥补ping的特点,我们通常将ping和telnet一起来使用,既可以通过ping检查网络连通性,也可以通过telnet指定端口。那么,除了它们,还有哪些工具可以用来测试端口连通性呢?这里给大家分享一下其他的工具。
-
47
-
35
虚拟网络排查问题困难,传统的 traceroute 等工具很难起到太大作用,大部分情况下都需要到宿主机、混合云网关上抓包来 troubleshooting,耗时又费力。有些场景中包的传送路径比较长(如跨域、混合云等),可能丢包的地方比较多,更增加了...
-
26
割点与桥 在一个无向连通图中,若将某个点及其相连的边删除后,图就不连通了,则这样的点被称为割点。 在一个无向连通图中,若将某条边删除后,图就不连通了,则这样的边被称为割边,即桥。 在一张图...
-
7
16 April 2021 / docker #docker 批量绑定和导出端口 docker-compose.yml的参数是: ports: - "3000" - "3000-3005" - "80...
-
5
使用mtr查看网络连通性 发表于 2021-08-02...
-
5
telnet命令测试邮件服务器连通性 | Lenix Blog telnet命令测试邮件服务器...
-
4
telnet命令是TELNET协议的用户接口,它支持两种模式:命令模式和会话模式; 虽然telnet支持许多命令,但大部分情况下,我们只是使用它查看目标主机是否打开了某端口(默认是23); 【转】使用telnet测试...
-
6
...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK