python curl 控制設備
先前做出的 php 版的 curl 控制設備只能使用網頁的模式,這次改成用 python ,原因很簡單可以利用 command 來發送命令,對於系統管理而言我們會需要許多指令來整合運作,程式如下
on.py
# -*- coding: utf-8 -*-
import pycurl
#from urllib import urlencode
github_url = '192.168.16.206/rpc_call'
postfields = "call=function&name=#0,0,0,0,0,0,0,system,projector,write,on&actfunc=custom_function_call_function"
c = pycurl.Curl()
c.setopt(pycurl.CONNECTTIMEOUT, 2)
c.setopt(pycurl.URL, github_url)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS,postfields)
c.perform()
print postfields
off.py
# -*- coding: utf-8 -*-
import pycurl
#from urllib import urlencode
github_url = '192.168.16.206/rpc_call'
postfields = "call=function&name=#0,0,0,0,0,0,0,system,projector,write,standby&actfunc=custom_function_call_function"
c = pycurl.Curl()
c.setopt(pycurl.CONNECTTIMEOUT, 2)
c.setopt(pycurl.URL, github_url)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS,postfields)
c.perform()
print postfields
on.py
# -*- coding: utf-8 -*-
import pycurl
#from urllib import urlencode
github_url = '192.168.16.206/rpc_call'
postfields = "call=function&name=#0,0,0,0,0,0,0,system,projector,write,on&actfunc=custom_function_call_function"
c = pycurl.Curl()
c.setopt(pycurl.CONNECTTIMEOUT, 2)
c.setopt(pycurl.URL, github_url)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS,postfields)
c.perform()
print postfields
off.py
# -*- coding: utf-8 -*-
import pycurl
#from urllib import urlencode
github_url = '192.168.16.206/rpc_call'
postfields = "call=function&name=#0,0,0,0,0,0,0,system,projector,write,standby&actfunc=custom_function_call_function"
c = pycurl.Curl()
c.setopt(pycurl.CONNECTTIMEOUT, 2)
c.setopt(pycurl.URL, github_url)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS,postfields)
c.perform()
print postfields
留言
張貼留言