目錄:唯一標識問題
唯一標識資料採集**邏輯
api驗證(對稱加密 )
唯一標識問題
客戶端方式面臨的問題:
需要選出乙個唯一的字段,作為唯一標識來區分伺服器資訊解決問題的過程:
需要給上架的伺服器分配唯一的主機名
將伺服器的主機名錄入到cmdb
在分配給技術之前,需要執行下採集程式,此時收集的資料都是原始的
可以將原始資料中的hostname儲存到乙個檔案中,以後,我們再向後端post資料的時候,以檔案中的hostname為乙個標準
回到目錄
唯一標識資料採集**邏輯
class
agent
(base)
:def
collect
(self)
:# 採集功能
res = pluginsmanager(
).execute(
)# 採集好主機資訊
hostname = res[
'basic'][
'data'][
'hostname'
]# 獲取採集的主機名
info =
open
(os.path.join(settings.basedir,
'conf/cert'),
'r', encoding=
'utf-8'
).read(
)# 獲取檔案儲存好的主機名
ifnot info.strip():
# 如果檔案中沒有儲存主機名,說明不是以第一次採集
with
open
(os.path.join(settings.basedir,
'conf/cert'),
'w', encoding=
'utf-8'
)as f:
# 將採集好的主機名儲存到檔案中
f.write(hostname)
else
:# 否則將檔案中儲存的主機名為標準發給api
res[
'basic'][
'data'][
'hostname'
]= info
for k, v in res.items():
print
(k, v)
self.post_info(res)
api驗證(對稱加密 )
客戶端**:
import requests
import time
import hashlib
client_time = time.time(
)# 客戶端當前時間
key =
'asdlkfjlasjgsdgadsf'
# 使用者的對應key
tmp =
"%s|%s"
%(key, client_time)
# 拼接key
# md5加密
m = hashlib.md5(
)m.update(
bytes
(tmp, encoding=
'utf-8'))
res = m.hexdigest(
)info =
"%s|%s"
%(res, client_time)
# 將要傳送的內容拼接
print
(info)
res = requests.get(
'', headers=
)print
(res.text)
服務端**:
import hashlib
import time
key =
'asdlkfjlasjgsdgadsf'
defasset
(request)
:if request.method ==
'get'
: server_time = time.time(
)# 獲取伺服器時間
# 獲取客戶端傳送過來的md5加密後的key,以及客戶端的時間
# (第一關)當客戶端與服務端時間差10s以上時
'api介面超時'
)# 拼接服務端儲存的使用者key和客戶端發過來的時間
tmp =
"%s|%s"
%(server_key, client_time)
# 加密過程
m = hashlib.md5(
) m.update(
bytes
(tmp, encoding=
'utf-8'))
server_md5_key = m.hexdigest(
)# (第二關)根據客戶端時間md5加密後的字串與客戶端md5加密後的字串進行比較
'非法請求'
)# (第三關,可以將使用者傳送過來的key使用redis進行儲存,當key重複時,拋棄請求)
(request.body)
回到目錄 Forms 身份驗證
配置應用程式使用 forms 身份驗證 如果應用程式的根目錄中有 web.config 檔案,請開啟該檔案。複製 在system.web元素中,建立乙個authentication元素,並將它的mode屬性設定為 forms,如下面的示例所示 複製 在authentication元素中,建立乙個fo...
WebService身份驗證
web service身份驗證解決方案一 通過通過soap header身份驗證。1.我們實現乙個用於身份驗證的類,檔名mysoapheader.cs mysoapheader類繼承自system.web.services.protocols.soapheader。且定義了兩個成員變數,userna...
WebServices身份驗證
最近遇到乙個問題,暴露在網路上的web service如何做身份驗證,而不被其他人說是用。mysoapheader.cs類 using system using system.collections.generic using system.linq using system.web namespa...