File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 14
14
BS = 8192 # 接收数据缓冲大小
15
15
ADDR = (HOST , PORT )
16
16
glnr = "zabbix"
17
+ COD = 'utf-8'
17
18
18
19
tcpSerSock = socket (AF_INET , SOCK_STREAM ) # 创建TCP服务器套接字
19
20
tcpSerSock .setsockopt (SOL_SOCKET , SO_REUSEADDR , 1 )
31
32
try :
32
33
data = tcpCliSock .recv (BS ) # 连续接收指定字节的数据,接收到的是字节>数组
33
34
if data : # 如果数据空白,则表示客户端退出,所以退出接收
34
- print ("客户端发送的内容:" ,data .decode ('utf-8' ))
35
+ print ("客户端发送的内容:" ,data .decode (COD ))
35
36
date = time .strftime ('%Y-%m-%d %H:%M:%S' , time .localtime (time .time ()))
36
- if glnr .encode ('utf8' ) in data :
37
- dd = "./dingding.py {}" .format (data .decode (encoding = 'UTF-8' ), 'ignore' )
37
+ if glnr .encode (COD ) in data :
38
+ dd = "./dingding.py {}" .format (data .decode (encoding = 'UTF-8' ), errors = 'ignore' )
38
39
p = subprocess .call (dd , shell = True )
39
40
if p == 0 :
40
41
time .sleep (4 )
45
46
else :
46
47
print ("忽略发送:{}" .format (date ))
47
48
msg = "YES"
48
- tcpCliSock .send (msg .encode ('utf8' )) # 向客户端状态数据
49
+ tcpCliSock .send (msg .encode (COD )) # 向客户端状态数据
49
50
print ("=" * 30 )
50
51
else :
51
52
break
You can’t perform that action at this time.
0 commit comments