此shell特点: 
1、不屏闭主控台,以免新手弄错导致自己都进不了系统。 
2、可以按网段或IP限制登录(在/etc/telhosts文件中定义),并可定义此网段或IP的TELNET个数(只有IP第四个字段可以设为*。要让每个字段都可以设为*,会使shell复杂,没必要)。 
3、仿照许可登录的判断方法,增几条语句后,可以指定拒绝登的IP,这部分我没写,因为只要你不定义许可登录,事实上用户根本就登不上来。 
4、加了一个登录时间许可判断。 
使用方法: 
把下面SHELL加到/etc/profile 文件最后,并编缉/etc/telhosts文件,加入类似如下内容,并赋权限为644: 
#/etc/telhosts文本样例 
# 用户名 IP地址 许可登录个数 
allow root 18.129.32.140 5 
allow root 18.129.32.* 10 
下面这段shell 请加入到 /etc/profile 最后 
echo "login check ..." 
TIME=`date '+%Y%m%d-%H:%M:%S'` #取当前时间 
TTY=`tty | cut -f3 -d'/'|sed "s/not a tty/not_a_tty/"` #取终端号 
IP3=`who -mx|awk -F ' ' '{print $6}'|cut -f1-3 -d'.'` #取IP前3个字节 
IP4=`who -mx|awk -F ' ' '{print $6}'|cut -f1-4 -d'.'` #取IP全址 
FLAG=`awk -F ' ' '{print $1,$2,$3,$4}' /etc/telhosts |  
grep -c "^allow $LOGNAME $IP3.*"` 
if [ "$FLAG" = "1" ] # FLAG=1 表示允许整个网段telnet 
then MAXTERM=`awk -F ' ' '{print $1,$2,$3,$4}' /etc/telhosts |  
grep "^allow $LOGNAME $IP3.*"|awk -F ' ' '{print $4}'` 
TERMNUM=`who -x|grep " $IP3."|grep -c "^$LOGNAME "` 
else MAXTERM=`awk -F ' ' '{print $1,$2,$3,$4}' /etc/telhosts |  
grep "^allow $LOGNAME $IP4"|awk -F ' ' '{print $4}'` 
TERMNUM=`who -x|grep " $IP4"|grep -c "^$LOGNAME "` 
fi 
if [ "x$IP4" = "x" ] # IP4 为空,认为是主控台登录 
then MAXTERM=99; IP4=localhost # 置MAXTERM=99,置主控台标志 
fi 
if [ ! "$MAXTERM" ] # 检查是否授权 
then echo "$IP4 未被授权,请与管理员联系 !" 
exit 1 # exit后的返回数可以没有,不是必须的 
fi 
if [ $TERMNUM -gt "$MAXTERM" ] # 检查是否超额定注册数 
then 
echo "超过许可终端数 !" 
exit 2 
fi 
if [ $TIME -lt 0150 -o $TIME -gt 2300 ] # 检查是否在许可工作时间 
then 
if [ "$IP4" != "localhost" ] 
then echo "限时登录" 
exit 3 
fi 
fi 
              
标签:


