Python3如何在服務(wù)器打印資產(chǎn)信息
python3 在服務(wù)器上打印資產(chǎn)信息
pip3 install prettytable
url 為 資產(chǎn)信息接口地址,返回為json信息。
# encoding=utf-8 import getopt import sys import prettytable as pt import requests import json def main(argv): try: options, args = getopt.getopt(argv, "n:", ["name=", ]) except getopt.GetoptError: sys.exit() for option, value in options: if option in ("-n", "--name"): url = 'http://xxxxxxxx/list' try: headers = {'Content-Type': 'application/json'} r = requests.post(url, data=json.dumps({"name": value}), headers=headers) if r.status_code == 200: data = r.json() tb = pt.PrettyTable() tb.field_names = ["主機(jī)名", "外網(wǎng)IP"] tb.align["主機(jī)名"] = "l" tb.align["外網(wǎng)IP"] = "l" for i in data: tb.add_row([i["_id"], i["out_ip"]]) print(tb) else: print("獲取信息錯(cuò)誤") except Exception as e: print(e) if __name__ == '__main__': main(sys.argv[1:])
結(jié)果
執(zhí)行: /usr/bin/python3.6 test.py -n test
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
全CPU并行處理Pandas操作Pandarallel更快處理數(shù)據(jù)
我們在處理數(shù)據(jù)時(shí),通常小的數(shù)據(jù)對處理速度不敏感,但數(shù)據(jù)量一大,頓時(shí)會感覺數(shù)據(jù)處理效率不盡如人意,今天介紹的pandarallel就是一個(gè)簡單高效的Pandas并行工具,幾行代碼就可以提高數(shù)據(jù)處理效率,2024-01-01Python中np.percentile和df.quantile分位數(shù)詳解
分位數(shù)(Quantile)亦稱分位點(diǎn)是指將一個(gè)隨機(jī)變量的概率分布范圍分為幾個(gè)等份的數(shù)值點(diǎn),下面這篇文章主要給大家介紹了關(guān)于Python中np.percentile和df.quantile分位數(shù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05pycharm打開chrome自動退出錯(cuò)誤的解決方法
這篇文章主要給大家介紹了關(guān)于pycharm打開chrome自動退出錯(cuò)誤的解決方法,文中通過實(shí)例代碼以及圖文將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07Python基于smtplib模塊發(fā)送郵件代碼實(shí)例
這篇文章主要介紹了Python基于smtplib模塊發(fā)送郵件代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05使用Python?matplotlib繪制簡單的柱形圖、折線圖和直線圖
Matplotlib是Python的繪圖庫, 它可與NumPy一起使用,提供了一種有效的MatLab開源替代方案,下面這篇文章主要給大家介紹了關(guān)于使用Python?matplotlib繪制簡單的柱形圖、折線圖和直線圖的相關(guān)資料,需要的朋友可以參考下2022-08-08