可以通过打请求的方式管理ss-server的port-passwd信息,文档
If you want to build a user management system, Shadowsocks provides an API that allows you to add/remove ports on the fly, as well as get transfer statistics from Shadowsocks.
If you simply want to add multiple users without changing them on the fly, you can check this tutorial.
Notice: only Python and libev versions support this feature.
Setup
Enable manager API by specifying --manager-address
, which is either a Unix socket or an IP address:
# Use a Unix socket
ssserver --manager-address /var/run/shadowsocks-manager.sock -c tests/server-multi-passwd.json
# Use an IP address
ssserver --manager-address 127.0.0.1:6001 -c tests/server-multi-passwd.json
`</pre>
For security reasons, you should use Unix sockets.
When manager is enabled, [workers](https://github.com/shadowsocks/shadowsocks/wiki/Workers) and [graceful restart](https://github.com/shadowsocks/shadowsocks/wiki/Graceful-shutdown-and-restart) are disabled.
## [](https://github.com/shadowsocks/shadowsocks/wiki/Manage-Multiple-Users#protocol)Protocol
You can send UDP data to Shadowsocks.
<pre>`command[: JSON data]
`</pre>
To add a port:
<pre>`add: {"server_port": 8001, "password":"7cd308cc059"}
`</pre>
To remove a port:
<pre>`remove: {"server_port": 8001}
`</pre>
To receive a pong:
<pre>`ping
`</pre>
Shadowsocks will send back transfer statistics:
<pre>`stat: {"8001":11370}
`</pre>
## [](https://github.com/shadowsocks/shadowsocks/wiki/Manage-Multiple-Users#example-code)Example Code
Here's code that demonstrates how to talk to the Shadowsocks server:
<pre>`import socket
cli = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
cli.bind('/tmp/client.sock') # address of the client
cli.connect('/var/run/shadowsocks-manager.sock') # address of Shadowsocks manager
cli.send(b'ping')
print(cli.recv(1506)) # You'll receive 'pong'
cli.send(b'add: {"server_port":8001, "password":"7cd308cc059"}')
print(cli.recv(1506)) # You'll receive 'ok'
cli.send(b'remove: {"server_port":8001}')
print(cli.recv(1506)) # You'll receive 'ok'
while True:
print(cli.recv(1506)) # when data is transferred on Shadowsocks, you'll receive stat info every 10 seconds
转载请注明来源链接 http://just4fun.im/2017/01/07/ss-e5-a4-9a-e7-94-a8-e6-88-b7-e7-ae-a1-e7-90-86/ 尊重知识,谢谢:)