#!/bin/bash

# 显示当前PPP连接状态
echo "当前PPP连接状态："
pppoe-status

# 获取当前PPP连接的接口
PPP_INTERFACES=$(ifconfig | grep -o -E 'ppp[0-9]+')

# 显示每个PPP接口的详细信息
echo "详细连接信息："
for IFACE in $PPP_INTERFACES; do
  echo "接口：$IFACE"
  
  # 获取PPP连接的对端IP地址
  PEER_IP=$(ifconfig $IFACE | grep 'P-t-P' | awk '{print \$3}' | cut -d: -f2)
  echo "对端IP地址：$PEER_IP"
  
  # 获取PPP连接的本地IP地址
  LOCAL_IP=$(ifconfig $IFACE | grep 'inet addr' | awk '{print \$2}' | cut -d: -f2)
  echo "本地IP地址：$LOCAL_IP"
  
  # 从日志中查找客户端账号和对应的ISP账号
  LOG_ENTRY=$(grep $IFACE /var/log/ppp.log | grep 'authenticated by' | tail -n 1)
  CLIENT_ACCOUNT=$(echo $LOG_ENTRY | awk '{print $NF}')
  ISP_ACCOUNT=$(grep "^${CLIENT_ACCOUNT}" /etc/ppp/account_mapping | awk '{print \$2}')
  
  echo "客户端账号：$CLIENT_ACCOUNT"
  echo "对应的ISP账号：$ISP_ACCOUNT"
  echo "-----------------------------"
done
