加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sock_serv.py 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
mr.github 提交于 2015-03-17 11:56 . simple rpc call through tcp socket
import socket, sys, os
import subprocess
from commands import getoutput
def exec_cmd(cmd):
p = subprocess.Popen(['C:\\Windows\\System32\\cmd.exe', cmd], shell=True)
p.wait()
out, err = p.communicate()
if not err:
return err
return out
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()
def start_chat():
address = ('0.0.0.0', 1989)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(address)
s.listen(5)
c, addr = s.accept()
print 'CONNECTION:', addr
while True:
cmd = c.recv(512)
cmd = cmd.strip('\r\n ')
print 'cmd:[%s]' % cmd
if cmd == 'quit':
c.close()
if cmd == 'cmd':
os.system("cmd.exe")
s.close()
if __name__ == '__main__':
simple_rpc()
#start_chat()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化