ARM40-A5应用——探测holer服务的状态
2018.11.24
版权声明:本文为博主原创文章,允许转载。
holer 是一个内网穿透工具,基于holer,可以通过ssh,连接处于内网的ARM40设备。
当有大量设备运行时,需要掌握 holer 服务的运行状态。
一、探测holer服务的状态
建议在ubuntu上运行本探测程序。并且需要安装 expect,例如 apt install expect。
探测程序共包含3个文件:
holer.list holer_online_check.sh ssh_expect.sh
其中 holer.list 中为需要检查的holer端口号的列表,例如:
#holerlist
PORT1=63001
PORT2=63013
PORT3=63017
PORT4=63021
PORT5=65039
PORT6=63023
PORT7=635646
ssh_expect.sh 文件内容如下:
#!/usr/bin/expect
set port [lindex $argv 0]
set timeout 30
spawn ssh -o BatchMode=yes -p $port armholer@holer.org
expect eof
exit
holer_online_check.sh 文件内容如下:
#!/bin/sh
DIR=`pwd`
HOLER_DIR="$DIR/holer.list"
PORT=null
if [ -e $HOLER_DIR ]; then
cat $HOLER_DIR
echo
cat $HOLER_DIR | while read eachline
do
PORT=`echo $eachline | awk '/PORT/ {print $1}' | cut -d '=' -f 2`
if [ "$PORT" != "" ]; then
$DIR/ssh_expect.sh $PORT | while read holeret
do
echo $holeret | \
echo $holeret | \
awk '/Permission/ {print "'$PORT' OK"} \
/Connection/ {print "'$PORT' NOK"} \
/Bad/ {print "'$PORT' Bad"} \
/Host key/ {print "'$PORT' OK"} \
/authenticity/ {print "'$PORT' try"}'
done
fi
done
fi
holer_online_check.sh 解析:
(1)从holer.list文件逐个获取端口号,例如 PORT=“63001”;
(2)运行 ssh_expect.sh 63001,其中主要是
ssh -o BatchMode=yes -p 63001 armholer@holer.org
(3)holer_online_check.sh 读取返回结果,返回的字符串可能如下:
ret: Permission denied (publickey,password,keyboard-interactive). #holer通
ssh_exchange_identification: Connection closed by remote host #holer不通
ssh_exchange_identification: read: Connection reset by peer #holer不通
ssh: connect to host holer.org port 65013: Connection refused #holer不通
ssh_exchange_identification: Connection timed out #超时,建议重试
Host key verification failed. #通,可手动登录更新ESA
The authenticity of host '[holer.org]: ([121.196.199.47]:)' can't be established. #需手动登录更新ESA
Bad port '630112' #端口号有误
(3)根据返回结果,判断holer服务的状态:OK、NOK 或 Bad。
二、测试情况
运行 holer_online_check.sh,测试如下:
#holerlist
PORT1=63001
PORT2=63013
PORT3=63017
PORT4=63021
PORT5=65039
PORT6=63023
PORT7=635646
63001 NOK
63013 OK
63017 OK
63021 OK
65039 OK
63023 NOK
635646 Bad
可见:
63001、63023 不通;
63013、63017、63021、65039 通;
635646端口有误。
参考文章:
ARM40-A5应用——使用holer访问内网的ARM40
使用Holer从公网SSH访问内网的Linux系统
https://www.cnblogs.com/witpool/p/8999134.html
https://blog.youkuaiyun.com/wangudongdong/article/details/80216603
Holer一款局域网服务器代理到公网的内网穿透工具
https://blog.youkuaiyun.com/wangudongdong/article/details/80036880
What is holer
https://github.com/Wisdom-Projects/holer
荟聚计划:共商 共建 共享 Grant