{"id":13775924,"url":"https://github.com/elder-wu/ssserverdevicelimit","last_synced_at":"2025-05-11T08:34:26.213Z","repository":{"id":149376536,"uuid":"134092683","full_name":"Elder-Wu/SSServerDeviceLimit","owner":"Elder-Wu","description":"可以让Shadowsocks服务器限制某个端口的设备连接数，防止有人恶意分享ss账号","archived":false,"fork":false,"pushed_at":"2019-12-23T06:27:01.000Z","size":194,"stargazers_count":23,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-03T17:12:21.667Z","etag":null,"topics":["shadowsocks","shadowsocks-server","shadowsocksr"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Elder-Wu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-19T19:40:18.000Z","updated_at":"2023-09-23T09:07:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"95228b64-34c6-4252-a9a6-8ffb1bf663fb","html_url":"https://github.com/Elder-Wu/SSServerDeviceLimit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elder-Wu%2FSSServerDeviceLimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elder-Wu%2FSSServerDeviceLimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elder-Wu%2FSSServerDeviceLimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elder-Wu%2FSSServerDeviceLimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Elder-Wu","download_url":"https://codeload.github.com/Elder-Wu/SSServerDeviceLimit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225031374,"owners_count":17410053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["shadowsocks","shadowsocks-server","shadowsocksr"],"created_at":"2024-08-03T17:01:54.624Z","updated_at":"2024-11-17T11:30:35.603Z","avatar_url":"https://github.com/Elder-Wu.png","language":"Python","funding_links":[],"categories":["\u003ca id=\"d03d494700077f6a65092985c06bf8e8\"\u003e\u003c/a\u003e工具"],"sub_categories":["\u003ca id=\"cb16466a31a167bb61f39e2a4a85f449\"\u003e\u003c/a\u003eShadowsocks"],"readme":"# SSServerDeviceLimit\nThis tool only used for ss-server not ssr-server.     \n可以让你的SS服务器限制某个端口的设备连接数，防止有人恶意分享账号，亲测有效，不是SSR服务器!\n\u003cp\u003e原理:Linux中通过iptables进行端口和IP的过滤，俗称防火墙 \n  \n[iptables简明教程](https://www.cnblogs.com/ggjucheng/archive/2012/08/19/2646466.html)\n\n![iptables规则](iptables.jpg)\n\n### 运行截图\n![未使用状态](never_used.png)\n![正常使用](normal_use.png)\n![设备连接数量达到极限](device_full.png)\n![端口异常](all_device_limit.png)\n\n\n# 使用方法\n使用前提：你的Linux服务器已经安装了SS server端，还需要安装iptables\n\n## 1.配置Shadowsocks服务\n在/etc目录下创建文件shadowsocks.json，文件内容如下:\n```json\n{\n  \"server\":\"0.0.0.0\",\n  \"local_address\": \"127.0.0.1\",\n  \"local_port\":1080,\n  \"port_password\":{\n    \"1111\": \"sfaewgsav\",\n    \"2222\": \"sgervthss\",\n    \"3333\": \"htehsdhst\",\n    \"端口号\": \"密码\",\n    \"端口号\": \"密码\",\n    \"端口号\": \"密码\",\n    \"端口号\": \"密码\",\n    \"端口号\": \"密码\"\n  },\n  \"timeout\":300,\n  \"method\":\"aes-256-cfb\",\n  \"fast_open\": false,\n  \"device_limit\":{\n    \"1111\":5,\n    \"端口号\":限制的设备数量\n  }\n}\n```\n\u003cp\u003e在port_password中配置多个端口号和对应的密码，端口号最好不要选用特殊端口，比如22(ssh)，80(http)，记住，这里的端口号一旦分配，就不要轻易删除。否则就要自己通过iptables来删除掉无用的规则\n\u003cp\u003edevice_limit中填写需要限制的端口号和设备数量，上面写的意思就是1111端口号最多只能有5个设备同时登录，可以不写，默认就是1\n\n##### 需要注意的是，device_limit中填写的端口号必须出现在port_password中\n\n## 2.重启Shadowsocks服务\n##### 配置开机启动，在/etc/rc.local中加入下面的内容\n```commandline\nssserver -c /etc/shadowsocks.json --user nobody -d restart\n```\n\u003cp\u003e-c ss配置文件的路径，本例的路径是/etc/shadowsocks.json\n\u003cp\u003e--user 使用非root用户运行ss服务，可以确保服务器安全。这里是nobody用户\n\u003cp\u003e-d daemon运行模式，这里是restart命令，常用的还有start,stop等命令\n\n## 3.配置Linux的crontab任务列表\n先将本项目中的ssdevicelimit.py拷贝到本地，放到/etc目录下，与shadowsocks.json在同一个目录\n##### 编辑Linux中的crontab任务\n```commandline\ncrontab -e\n```\n##### 输入如下内容\n```commandline\n#解决crontab报错：service: commond not found,是因为环境变量的问题\nPATH=/sbin:/bin:/usr/sbin:/usr/bin\n\n#每天0点清空root用户的mail邮件\n0 0 * * * rm -f /var/mail/root\n\n#每分钟都更新一下ss的端口限制\n* * * * * cd /etc/; python3.6 ssdevicelimit.py\n```\n\u003cp\u003e必须使用python3.x版本，因为我的服务器上python3的环境变量是python3.6，所以上面我写成了python3.6，请根据你自己的python环境变量名来改\n\n##### 最后保存，然后你就等着那些恶意分享SS账号的人抱怨吧：\n# 为什么账号不能用了，之前不是好好的吗，FUCK！！！\n\n## 后续\n1. 以上操作都确保无误的话，想限制某个端口的设备数量，只要修改```shadowsocks.json```中的内容就可以了，然后重启ss服务就可以生效\n2. 通过 ```tail -n 100 /var/mail/root``` 查看当前各端口的使用情况，以及使用端口的设备IP\n3. 有其他问题请提issue\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felder-wu%2Fssserverdevicelimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felder-wu%2Fssserverdevicelimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felder-wu%2Fssserverdevicelimit/lists"}