I want to incorporate NetLimiter into my Python program using NetLimiter API. But I haven't found any docs about the API. I have found this link only which doesn't provide any sample program or docs on how to use it.
Does anyone know how to use NetLimiter API in python?
For that you need to install netifaces library in python,
Here is the damo i have made
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)