盒子
盒子

Python脚本实现SS密码自动更新

mycmd下新建ss.bat

1
2
3
4
# 更新密码
ssr/ss.py
# 启动 SS
ssr/ss.exe

CodeBak

File:ss.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import zbar
from PIL import Image
import urllib
import cStringIO
import base64
import sys,os


URL = ('http://freess.org/images/servers/jp03.png')
# create a reader
scanner = zbar.ImageScanner()
# configure the reader
scanner.parse_config('enable')
# obtain image data
imgfile = cStringIO.StringIO(urllib.urlopen(URL).read())
pil = Image.open(imgfile).convert('L')

width, height = pil.size
raw = pil.tostring()
# wrap image data
image = zbar.Image(width, height, 'Y800', raw)
# scan the image for barcodes
scanner.scan(image)
# extract results
for symbol in image:
# do something useful with results
# print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
pwd = base64.b64decode(symbol.data[5:])[12:20]
# with open('p1.txt', 'w') as f:
# f.write(pwd)

f=open('D:\\green\\ShadowsocksR\\gui-config.json','r+')
flist=f.readlines()
flist[25]=' \"password\" : \"'+pwd+'\",\n'
f=open('D:\\green\\ShadowsocksR\\gui-config.json','w+')
f.writelines(flist)


# clean up
del(image)
关注
公众号