-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheve_ng_api.py
52 lines (44 loc) · 1.51 KB
/
eve_ng_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
# Function to login to Eve-NG and return cookies for session
def login_to_eve_ng():
url = "http://192.168.1.148/api/auth/login"
data = {
'username': 'admin',
'password': 'eve',
'html5': '-1'
}
try:
response = requests.post(url, json=data)
if response.status_code == 200:
return response.cookies
else:
print(f"Login failed: {response.status_code} - {response.text}")
return None
except Exception as e:
print(f"Login error: {str(e)}")
return None
LAB_ID = "Jezlol.unl" # Define your LAB ID here globally
# Function to get devices from Eve-NG Lab
def get_lab_devices():
cookies = login_to_eve_ng()
if not cookies:
return []
url = f"http://192.168.1.148/api/labs/{LAB_ID}/nodes"
try:
response = requests.get(url, cookies=cookies)
if response.status_code == 200:
devices = response.json().get('data', {})
if isinstance(devices, dict):
return [
{'id': node_id, 'name': node_info['name'], 'type': node_info['type']}
for node_id, node_info in devices.items()
]
else:
print(f"Unexpected data format: {devices}")
return []
else:
print(f"Failed to get devices: {response.status_code}")
return []
except Exception as e:
print(f"Error fetching devices: {str(e)}")
return []