English | 中文
-
This script is based on vnstat traffic statistics. vnstat only starts counting traffic after installation!
-
TC mode cannot prevent DDoS traffic consumption, traffic consumption speed is still relatively fast! PRs to fix this are welcome (if possible).
-
If you encounter GitHub API rate limit issues, try the following solutions:
- Use the raw content URL to download the script
- Wait for the API limit to reset (usually 1 hour)
- Use a personal access token to increase API quota
- Manually download and run the script
-
The script runs with root privileges by default. For non-root users, ensure sudo privileges and prefix all commands with sudo.
-
If you encounter issues, check the log file (/root/traffic_monitor.log) for more information.
-
Regularly check for script updates to get new features and bug fixes.
-
For specific VPS providers, configuration adjustments may be needed to adapt to their billing models.
-
Speed limits in TC mode may not be precise, actual speeds may vary slightly.
-
Shutdown mode will completely cut off network connections, use with caution.
-
It's recommended to regularly backup the configuration file (traffic_monitor_config.txt).
Q: Why does my traffic statistics seem inaccurate? A: Ensure vnstat is correctly installed and has been running for some time. Newly installed vnstat needs time to collect accurate data.
Q: How to change the set configuration? A: Re-run the script, it will prompt you whether to modify the existing configuration.
Q: What if SSH connection becomes slow in TC mode? A: Try increasing the speed limit value in TC mode.
Q: How to completely uninstall the script? A: Use the following commands:
sudo pkill -f traffic_monitor.sh
sudo rm /root/traffic_monitor.sh /root/traffic_monitor_config.txt /root/traffic_monitor.log
sudo tc qdisc del dev $(ip route | awk '/default/ {print $5}') root
sudo curl -H "Accept: application/vnd.github.v3.raw" -fsSL "https://api.github.com/repos/ypq123456789/TrafficCop/contents/trafficcop.sh" | tr -d '\r' > /root/traffic_monitor.sh && chmod +x /root/traffic_monitor.sh && bash /root/traffic_monitor.sh && sudo curl -H "Accept: application/vnd.github.v3.raw" -fsSL "https://api.github.com/repos/ypq123456789/TrafficCop/contents/tg_notifier.sh" | tr -d '\r' > /root/tg_notifier.sh && chmod +x /root/tg_notifier.sh && bash /root/tg_notifier.sh
sudo curl -fsSL "https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/trafficcop.sh" | tr -d '\r' > /root/traffic_monitor.sh && chmod +x /root/traffic_monitor.sh && bash /root/traffic_monitor.sh && sudo curl -fsSL "https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/tg_notifier.sh" | tr -d '\r' > /root/tg_notifier.sh && chmod +x /root/tg_notifier.sh && bash /root/tg_notifier.sh
sudo curl -H "Accept: application/vnd.github.v3.raw" -fsSL "https://api.github.com/repos/ypq123456789/TrafficCop/contents/trafficcop.sh" | tr -d '\r' > /root/traffic_monitor.sh && chmod +x /root/traffic_monitor.sh && bash /root/traffic_monitor.sh
sudo tail -f -n 30 /root/traffic_monitor.log
sudo cat traffic_monitor_config.txt
sudo pkill -f traffic_monitor.sh
sudo curl -sSL https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/remove_traffic_limit.sh | sudo bash
- Automatically detects and selects the main network interface for traffic limiting.
- User selects traffic statistics mode (four options).
- User sets traffic calculation cycle (month/quarter/year) and start date.
- User inputs traffic limit and tolerance range.
- User selects limiting mode (TC mode or shutdown mode).
- For TC mode, user can set speed limit value.
- Script checks traffic consumption every minute, executes corresponding action when limit is reached.
- Automatically removes limit at the start of a new traffic cycle.
- Four comprehensive traffic statistics modes, adapting to various VPS billing methods.
- Customizable traffic calculation cycle and start date.
- Customizable traffic tolerance range.
- Interactive configuration, parameters can be modified at any time.
- Real-time traffic statistics prompts.
- TC mode ensures SSH connection remains usable.
- Shutdown mode provides stricter traffic control.
- Customizable speed limit bandwidth (TC mode).
TrafficCop now integrates Telegram Bot functionality, which can send the following notifications:
- Speed limit warnings
- Speed limit removal notifications
- New cycle start notifications
- Shutdown warnings
- Daily traffic reports
Supports custom hostnames, one bot can uniformly manage all your VPS!
To use this feature, provide your Telegram Bot Token and Chat ID during script configuration.
Telegram Bot Token is displayed when you create the bot.
Method to get Chat ID: https://api.telegram.org/bot${BOT_TOKEN}/getUpdates
${BOT_TOKEN} is your Telegram Bot Token
Chat ID can also be obtained through bots, which is simpler, such as username_to_id_bot
One-click push script
sudo curl -H "Accept: application/vnd.github.v3.raw" -fsSL "https://api.github.com/repos/ypq123456789/TrafficCop/contents/tg_notifier.sh" | tr -d '\r' > /root/tg_notifier.sh && chmod +x /root/tg_notifier.sh && bash /root/tg_notifier.sh
View TG push scheduled execution log
sudo tail -f -n 30 /root/tg_notifier_cron.log
View current status
sudo tail -f -n 30 /tmp/last_traffic_notification
Kill all TG push processes
sudo pkill -f tg_notifier.sh && crontab -l | grep -v "tg_notifier.sh" | crontab -
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-200g && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-20g && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/ali-1T && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/az-15g && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/az-115g && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/GCP-625g && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/GCP-200g && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/alice-1500g && cat traffic_monitor_config.txt
sudo curl -o /root/traffic_monitor_config.txt https://raw.githubusercontent.com/ypq123456789/TrafficCop/main/asia-300g && cat traffic_monitor_config.txt
Star History Chart
https://t.me/+ydvXl1_OBBBiZWM1
Thank you very much for your interest in this project! Maintaining open-source projects indeed requires a significant investment of time and energy. If you find this project valuable, please consider offering some support, even if it's just the cost of a cup of coffee.
Your generous assistance will motivate me to continue improving this project and make it more practical. It will also allow me to focus more on contributing to the open-source community. If you're willing to provide sponsorship, you can do so through the following channels:
Alipay | |
---|---|