Code Monkey home page Code Monkey logo

v2iplimit's Introduction

V2IpLimit


Limiting the number of active users with IP (with xray logs)
Currently only tested with
Marzban And V2RayGen

Go to Marzban Version ♦️ Go to V2RayGen Version


Donation

If you found V2IpLimit useful and would like to support its development, you can donate on the following crypto network:
  • TRON network (TRX): TLARb1Ns5vA7pH6wqSyZGreDbGooS85Mi5

Thank you for your support!


If this program was useful for you, please give it a star ⭐

v2iplimit's People

Contributors

houshmand-2005 avatar nikita-safonov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

v2iplimit's Issues

عدم محاسبه دقیق زمان آنبن شدن یوزر

عرض سلام و خسته نباشید
وقتی یک یوزر بن میشه توی زمان مشخص شده آنبن نمیشه
من زمان ها رو به صورت دیفالت گذاشتم (چک 240 و بن بودن :210)
ولی متاسفانه توی اکثر مواقع یوزر قبل از 210 ثانیه مجدد اکتیو میشه
گاهی وقت 2 دقیقه و گاهی حتی بعد از یک دقیقه اکتیو میشه
من از نسخه مرزبان استفاده میکنم
لطفا این باگ رو بررسی و رفع کنید
پیشاپیش سپاسگذارم

load balance and tunnel(iptables) problem

سلام خوبی خسته نباشین
یه مشکلی که من در برنامه دیدم وقتی میایی سرور رو لودبالانس میکنی یا تانل میزنی برنامه دیگه کار نیمکنه یوزر و تعداد کاربران متصل رو نشون نمیده یا به تلگرام نمیفرسته کلا تشخیص نمیده کی با چه ایپی وصله یا چند نفر از کانفیگ در مرزبان استفاده میکنن
راهی واس حل مشکلش هست ؟

عدم نمایش کاربرهای فعال

اسکریپت به پنل مرزبان با موفقیت متصل می شود اما تعداد کاربر فعال را نمی تواند محاسبه کند و ۰ بر میگرداند

main server doesn't work

سلام. من همه مراحل رو به دقت پیش رفتم ولی خطای main server doesn't work میگیرم. دلیل و راهکارش چیه؟
server rejected WebSocket connection: HTTP 400
main server doesn't work

Node Notification

Hello Houshmand
I hope you're doing great!

As I am aware, when the logs are sent to telegram, it also notifies us of a certain node being disconnected which is what I am looking for. Now this problem might not be something everyone has faced but I believe it's a really good feature.

I want the log that is sent to telegram to contain only node notification not the IP Limit log. Like if a certain node is on a status except "connected" It would notify in the telegram bot. The two statuses are "Connecting" and "Error" which is seen whenever a node has some sort of problem.

I know this is not directly relevant to the project you have here but is it possible to have such a thing?

Please let me know,
I really appreciate it!

"Node number x doesn't work" message can be deleted.

سلام.
بعد از اینکه مرزبان قابلیت Enable/Disable نود ها رو اضافه کرده، بعضی نود ها که Disable هستن همچنان با اسکریپت V2IPLimit این پیام براشون ارسال میشه.
بنظرم اگر طوری بشه که نود های Disable تشخیص داده بشن و این پیام براشون ارسال نشه خیلی بهتر میتونه باشه.

Tunnel

Hi,
Thanks for your script, when i use tunnel to connect marzban it cant find user ip and it return tunnel server ip for user.
can we do something for that?

خروجی اسکریپت

درود با عرض خسته نباشید
میخواستم مقدار ایپی هایی که اسکریپت از پنل میگیره رو طی هر 1 دقیقه ذخیره کنم تو ی فایل تکست ولی خروجی درست رو نمیتونم بگیرم ممنون میشم یکم راهنمایی ام کنید
درضمن وقتی اسکریپت رو ران میکنم رو سرور خروجی که نشون میده معمولا کمتر و فرق داره با خروجی که تلگرام میفرسته میخواستم این رو هم بدونم داستانش چیه

file_name = "user_ip.txt"
    with open(file_name, "w") as file:
        file.write(str(user_ip))
    مقدار آخری رو چی بزارم که کل ایپی های متصل رو ذخیره کنه برام تو فایل
    
    با تشکر

cant run script in windows

سلام و عرض ادب
من یک سرور دارم که روی اون ویندوز سرور 2019 نصب هست
اسکریپت شما رو که اجرا میکنم چند تا ارور میده
اولیش این هست تو خط 11
ModuleNotFoundError: No module named 'pytz'

راهی وجود داره بشه از اسکریپت رو سرور ویندوزی استفاده کرد؟

اپدیت مرزبان

درود و خسته نباشید
مرزبان به نسخه 0.4.0 ارتقاع پیدا کرد ، ایا با نسخه فعلی اسکریپت سازگار هست؟ یا اپدیت میدید؟
باتشکر

اجرا نشدن اسکریپت بعد از خارج شدن از سرور

سلام
بعد از اینکه از سرور خارج میشم اسکریپت ادامه نمیده و stop میخوره
اگر یک اپشن دیگه هم اضافه کنید بهش طرف از محدودیت ای پیش بیشتر مصرف کرد و اکانتش غیر فعال شد بعد از یک تایم مشخص اکانتش خودکار فعال شه عالی میشه

Question

Hello Again,
I hope you're doing great!

I'm here with another question as always, sorry for bothering you.
I applied this script for a panel on a different VPS which the panel is not on that and it worked!
So is this the way it works? it doesn't matter where we run it?

Please let me know
Thanks a lot

Api

لطفا اگر ممکنه و وقت آزاد دارید برای این اسکریپت api ایجاد کنید تا بشه ازش استفاده بهتری کرد
با تشکر از زحمات شما

سوال

سلام وقت بخیر

من دو بار اسکنر فعال کردم این مشکلی نداره که؟یا چطوری میتونم یدونش قطع کنم.

چه کامند های برای بات تلگرام هست ممنون میشم راهنمایی کنید؟

telegram notification

درود با عرض خسته نباشید
من وقتی اسکریپت رو به صورت عادی ران میکنم بدون هیچ مشکلی تا ساعت ها کار میکنه ولی وقتی
"SEND_LOGS_TO_TEL": "True"
روشن میکنم چند تای اولی رو درست میفرسته توی تلگرام ولی بعد از چند تا این ارور رو میده

-----run------
Traceback (most recent call last):
  File "/root/V2IpLimit/Marzban/v2_ip_limit.py", line 627, in <module>
    job()
  File "/root/V2IpLimit/Marzban/v2_ip_limit.py", line 501, in job
    file.write(str(user_ip))
UnboundLocalError: local variable 'user_ip' referenced before assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/V2IpLimit/Marzban/v2_ip_limit.py", line 631, in <module>
    send_logs_to_telegram(ex)
  File "/root/V2IpLimit/Marzban/v2_ip_limit.py", line 106, in send_logs_to_telegram
    messages = message.split("\n")
AttributeError: 'UnboundLocalError' object has no attribute 'split'

و کلا اسکریپت از کار می افته لطفا چک کنید با تشکر

Bug

Hello Again,

The script doesn't enable users after they have exceeded the IP Limit.
It only disables them but doesn't enable them after the 4 minutes.

مشکل در شناسایی اتصال نود های مرزبان

سلام و خسته نباشید، خیلی ممنون بخاطر اسکریپت خوبتون من یکهفتس با اینکه نود هام داخل پنل وصل شده کامل ولی داخل ربات ارور Node number X doesn't work میگیرم لاگ رو هم که چک کردم این عبارت زیر رو دیدم، ممنون میشم راهنمایی کنید.
did not receive a valid HTTP response

بازم میگم نود ها بدون مشکل وصل هستن و کار میکنن...

Report a Bug (probably)

Hello and good day,

I've run the script and it's been working like a charm, thank you.

There is just one thing I noticed, when TIME_TO_CHECK is set to for example 300 and INACTIVE_DURATION is set to 240 the script does check for connections every 5 minutes and disable users who exceed the limit BUT it enables them way sooner than 4 minutes (what I observed through telegram logs was around a minute or so). I tried different timings, updating python to the latest version and even rerunning the screen after making changes to config.json file but the problem still persists.

I would appreciate if you address this issue since I'm not sure if it is because of my VPS configuration or the code itself, thanks.

It only shows some online users not all of them

Hi , I'm using the last version of marzban panel and encounter this problem that it only shows some online users not all of them. I thought maybe it could be IP_Location problem so I deleted that line from py file, the result was it showed all online users but with too many IPs (about 2-50) which as I checked are cloudflare lPs.
I live in Iran and I'm not using tunnel.
Can you help me to fix this problem?

مشکل در نود

با سلام

ممنون از اسکریپت خوبتون فقط مشکلی که من دارم این هست که داخل تلگرام به من ارور Node number 1 doesn't work میده و بنده 3 تا نود دارم و لیمیت آی پی اعمال نمیشه

راه حلی برای این موضوع هستش؟

Bug Report

Hello Again,
I hope you're doing well.

Sometimes it identifies a large number of IPs connected to a config like 25, 37 and 47. These are the numbers.
While only one person is using it.

Also, It disconnects users that have exceeded IP Limit but it doesn't enable them after the 4 minutes.

Please let me know what I should do
Thank you so very much for all your effort and time

از کار افتادن بعد از چند ساعت

سلام . من از اخرین نسخه مرزبان استفاده میکنم و از این اسکریپت استفاده میکنم اما بعد از چند ساعت از کار میفته و اعلام میکنه که کاربری اکتیو نیست اما بعد از استوپ کردن و دوباره استارت کردنش درست میشه
من از روش اول برای ران کردنش استفاده کردم (screen)
افراد دیگه هم همین مشکل رو داشتن و فکر میکنم همگانی هست
لطفا یه بررسی بکنید

Seperate Logs of Multiple VPS on 1 Telegram Bot

Hello there!
I hope you are doing great!
First of all, I wanna thank everyone who has helped in this amazing project.

I was wondering if we could add a tag in the log to seperate it from other servers logs in telegram bot, I am using the same telegram bot for multiple servers in terms of logs and it's hard to know which one is for which server so if we could add a tag or a letter, anything to seperate the logs of each server it would be really amazing!!!

Please let me know what you think,
Thanks a lot :)

1 VPS & Multiple Panels

Hello Again,
I hope you're doing great!

How can I run this script for multiple panels on 1 VPS?
Is it doable? Please guide me through it if you can.

I appreciate your time bro!
Thanks a lot

UsageTime Command

Hello Again,

This command " /UsageTime " doesn't work most of the times.
When I enter it, it says "User not found" while I write completely correct.
Uppercase and Lowercase Letters are written according to username and yet doesn't work.

Sometimes after I enter the command 10 times, it replies with the wrong time.
For instance, it says yesterday at 14:00 while the user has connected this morning.

Please let me know what I should do
Thank you for all your effort and time bro

Ipv6

عرض سلام و خسته نباشید
مرسی از اسکریپت خوبتون ، خیلی کاربردیه
فقط یه موردی که بهش برخوردم اینه که برنامه ipv6 رو شناسایی نمیکنه
توی xray-log آی پی هارو میزنه اما اسکریپت اونارو شناسایی نمیکنه

Wrong IP count in logs

Hello and good day,

I have done some research on the issue of the script logging incorrect numbers of connected IPs, which several other people have reported, and I would like to share my findings.

My setup consists of a master server and some nodes. Occasionally, some IPs connected to a node or the master server are missing from the Telegram logs. Restarting the Marzban service on the affected server fixes the issue temporarily, but it reoccurs after some time (hours or days) with the same or different nodes.

Moreover, when the script encounters a connection problem with a server, it attempts to reconnect to that server. However, I have noticed through Telegram logs that the script sometimes fails to detect connection problems, so it does not try to reconnect. This causes a drop in connected IPs. When the script finally detects and reconnects to the problematic server, everything returns to normal.

I am not sure if this is a problem with the Marzban or the Houshmand script, but I have observed that when the script reports a connection problem with a server, the users on that server remain connected.

I hope this helps to understand and resolve the problem.

Issue

Hello Again,
I hope you're doing well!

I was wondering if you've changed the script recently because I tried it today on a new VPS and it doesn't work!

root@TED:/V2IpLimit/Marzban# python3 v2_ip_limit.py
Traceback (most recent call last):
File "/V2IpLimit/Marzban/v2_ip_limit.py", line 12, in
import requests
ModuleNotFoundError: No module named 'requests'

Also I tried "chmod +x cronjob.sh v2_ip_limit.py"
None of them worked! No Log was sent to Telegram neither!

Please let me know what I should do...
Thank you so much

Running This on Windows

Hi

I was wondering how I can run this on my windows locally instead of linux.
Can you please guide me through It if It's possible?

I really appreciate It.

ارسال لاگ فقط برای تعداد خاصی آی‌پی متصل

سلام. ممنون از اسکریپت خوبی که تهیه کردید.
راهی هست که لاگ های ارسالی به ربات، فقط برای یوزر هایی که از تعداد خاصی IP متصل به بالا هستن ارسال بشه؟
مثلا فقط یوزر هایی که بیشتر مساوی 3 کاربر دارن لاگ ارسال بشه

مشکل در کانکشن های دیزیبل

سلام
اول که تشکر بابت اسکریپت کاربردی که نوشتید
فقط یه مشکل هست
همه چی به درستی کار میکنه و تشخیص میده که دوتا IP الان به یه کانکشن وصل هستن
کانشکن رو هم disable میکنه
ولی با اینکه کانکشن دیزیبل هست اما هر دو گوشی که باهاشون وصل بودم و باعث این دیزیبلی شدن
هر دو به سرور وصل میمونن
یعنی با اینکه کانکشن دیزیبل شده ولی ارتباطی قطع نمیشه (خیلی عجیبه)

Telegram getUpdates Unauthorized

Hi thanks for your script,

When I first deploy it i faced with such issue

https://api.telegram.org/<token>/getUpdates {'offset': None, 'timeout': 30}
{'ok': False, 'error_code': 401, 'description': 'Unauthorized'}

But other telegram funtions such as send_logs_to_telegram works well. So i add debug to dig into the code and found out this issue:

https://api.telegram.org/<token_part>GvALpM/sendMessage - send_logs_to_telegram
https://api.telegram.org/<token_part>GvALp/getUpdates {'offset': None, 'timeout': 30} - get_updates

M - is missing due to rstrip("/sendMessage"). M is also in rstrip. Issue on StackOverflow

"There is no active user" when setting up Xray to write logs to files

I found a problem. If the xray_config.json file specifies saving logs to files like this:

   "log": {
     "loglevel": "info",
         "access": "/var/lib/marzban-node/access.log",
         "error": "/var/lib/marzban-node/error.log"
   },

then the script does not work, it displays "There is no active user".
Right while the script was running, I deleted and added back the access and error entries, restarted Xray and the script either worked or stopped.

script can not detect ipv6

Hello
Thanks for your useful script.
The script works well for users that connected by ipv4 but some ISPs like irancell use ipv6 by default and script can not detect them. maybe it is because of x-ray core or... . please fix this issue or if it is not an issue of the script give me some fix tips.

A Command for Telegram Bot for Last Usage Time of A User

Hello again,

I know I have already asked you for a lot of features and you added them kindly :)
I just have an idea, if you don't have enough time to do it, I totally understand.

I think The Logs also state the last time a user has connected so it would be nice to add a command for telegram bot to know the last time a user has connected, something like this:
/UsageTime Username
Last Time Active: 13-06-23 I 02:10:00

I believe it can enhance the script, it would be a cool feature but the choice is yours.
Thank you again for everything you've done bro!

There is no active user

Hi. During the execution of the script, I get this result. Active users in fact about 10. Could you tell me what the problem might be?

-----run------
There is no active user
-----done-----

Error HTTP 400

I run the code but i see this error:

Establishing connection for node number 1
no close frame received or sent
server rejected WebSocket connection: HTTP 400
Node number 1 doesn't work
Establishing connection for node number 2
no close frame received or sent
server rejected WebSocket connection: HTTP 400

what is the problem?!

گزارش باگ

سلام و تشکر بابت این اسکریپت خوب فقط یک مشکلی که داری اینه که اگر از لودبالانسر(مثلا لودبالانسر هتزنر) استفاده بشه آیپی رو تشخیص نمیده، حتی یدونه هم حسابش نمیکنه اون آیپی رو اصلا انگار وجود نداره.
به بات تلگرامی هم نتونستم وصلش کنم ممنون میشم بیشتر راهنمایی کنید 🙏

اشتباه من

بعد از 3 ماه فهمیدم یک اشتباه کردم اینجا مینویسم شاید به درد کسی بخوره
کرون جاب رو گذاشته بودم هر 10 دقیقه اجرا شه. و همیشه میدیدم حدود 300 نفر متصل هستند.
در صورتی که فقط یک بار کرون جاب اجرا شه کافیه حالا 900 نفر نشون میده متصل هستند و آمار دقیق تر هست
با سپاس از هوشمند عزیر بابت این اسکریپت

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.