0 Star 0 Fork 231

rockylee/python-learn

forked from mktime/python-learn 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rpc_server.py 733 Bytes
一键复制 编辑 原始数据 按行查看 历史
mr.github 提交于 2015-03-17 11:56 . simple rpc call through tcp socket
import socket, sys, os
from commands import getoutput
def simple_rpc():
server_addr = ("0.0.0.0", 1989)
white_list = ["130.89.200.99", "136.24.224.4"]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(server_addr)
s.listen(5)
while True:
c, addr = s.accept()
print addr[0]
if addr[0] not in white_list:
c.send("forbidden")
c.close()
else:
cmd = c.recv(1024).strip("\r\n")
print "calc ..."
print cmd
ret = getoutput(cmd)
print ret
print "done ..."
c.send(ret)
print "after send"
c.close()
if __name__ == '__main__':
simple_rpc()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/isliwg/python-learn.git
git@gitee.com:isliwg/python-learn.git
isliwg
python-learn
python-learn
master

搜索帮助