这个问题困扰了我很久,终于在pppd的man文档里,发现了踪迹。在man中的SCRIPTS下有一系列的参数,其中PEERNAME就是登陆的用户名,并且在/etc/ppp/ip-up和/etc/ppp/ip-down里面记录一下就可以了,
发现ip-up被调用的时候是有命令行参数的,$6就是用户ip,于是在ip-up里面手工用echo命令写了一下,算是pptpd的比较完整日志,里面有时间,有来源ip,有用户名,有被分配的ppp的ip等
在/etc/ppp/下新建ip-up和ip-down的脚本并且添加执行权限
在ip-up中加入以下内容
#!/bin/sh
echo "##################################" >> /var/log/pptpd.log
echo "Now User $PEERNAME is connected!!!" >> /var/log/pptpd.log
echo "##################################" >> /var/log/pptpd.log
echo "time: `date -d today +%F_%T`" >> /var/log/pptpd.log
echo "clientIP: $6" >> /var/log/pptpd.log
echo "username: $PEERNAME" >> /var/log/pptpd.log
echo "device: $1" >> /var/log/pptpd.log
echo "***IP: $4" >> /var/log/pptpd.log
echo "assignIP: $5" >> /var/log/pptpd.log
即可
在ip-down中加入以下内容
#!/bin/sh
echo "#####################################" >> /var/log/pptpd.log
echo "Now User $PEERNAME is disconnected!!!" >> /var/log/pptpd.log
echo "#####################################" >> /var/log/pptpd.log
echo "time: `date -d today +%F_%T`" >> /var/log/pptpd.log
echo "clientIP: $6" >> /var/log/pptpd.log
echo "username: $PEERNAME" >> /var/log/pptpd.log
echo "device: $1" >> /var/log/pptpd.log
echo "***IP: $4" >> /var/log/pptpd.log
echo "assignIP: $5" >> /var/log/pptpd.log
echo "connect time: $CONNECT_TIME s" >> /var/log/pptpd.log
echo "bytes sent: $BYTES_SENT B" >> /var/log/pptpd.log
echo "bytes rcvd: $BYTES_RCVD B" >> /var/log/pptpd.log
sum_bytes=$(($BYTES_SENT+$BYTES_RCVD))
sum=`echo "scale=2;$sum_bytes/1024/1024"|bc`
echo "bytes sum: $sum MB" >> /var/log/pptpd.log
ave=`echo "scale=2;$sum_bytes/1024/$CONNECT_TIME"|bc`
echo "average speed: $ave KB/s" >> /var/log/pptpd.log
即可
转载于:https://blog.51cto.com/caogang440/977177