我想使用NetLimiter API将NetLimiter集成到我的Python程序中,但是我没有找到任何关于API的文档。我只找到了this link,它没有提供任何示例程序或如何使用它的文档。有人知道如何在python中使用NetLimiter API吗?
h7appiyu1#
为此,您需要在python中安装netifices库。这是我做的礼物
import netifaces import requests ip_address = netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr'] #Get the IP address of the machine where NetLimiter is installed and port api_url = f'http://{your_ip_address}:8282/nlapi/v1/' def send_request(method, endpoint, data=None): url = api_url + endpoint headers = {'Content-Type': 'application/json'} response = requests.request(method, url, headers=headers, json=data) if response.status_code == 200: return response.json() else: raise Exception(response.text) enter code here rules = send_request('GET', 'rules') print(rules) rule_data = { 'name': 'My Rule', 'direction': 'In', 'protocol': 'TCP', 'remoteAddress': '192.168.1.1', 'remotePort': '80', 'limit': 1024 } response = send_request('POST', 'rules', rule_data) print(response)
1条答案
按热度按时间h7appiyu1#
为此,您需要在python中安装netifices库。
这是我做的礼物