list pptpd user
16 Oct 2012!/usr/bin/python
from subprocess import Popen,PIPE
dicIP = {}
pppip = Popen("ip addr | grep inet | grep ppp |awk '{print $7,$4}'",shell=True,bufsize=1024,stdin=PIPE,stdout=PIPE).stdout
pppuser = Popen('''last | grep "$(date | cut -c1-10)" | grep ppp |awk '{print $2,$1,$3,$7,$8,$9,$10}' ''',shell=True,bufsize=1024,stdin=PIPE,stdout=PIPE).stdout
for eachLine in pppip.readlines():
#print eachLine.strip()
L1 = eachLine.split(' ')
dicIP[L1[0]] = L1[1].strip()
for eachLine in pppuser.readlines():
#print eachLine.strip()
L2 = eachLine.split(' ')
if L2[0] in dicIP:
print dicIP[L2[0]][:-3],eachLine.strip()
output like this:
192.167.XXX.XXX ppp2 username1 XXX.XXX.XXX.XXX 09:19 still logged in
192.167.XXX.XXX ppp1 username2 XXX.XXX.XXX.XXX 09:13 still logged in
192.167.XXX.XXX ppp0 username3 XXX.XXX.XXX.XXX 09:04 still logged in