Skip to content

Commit 545bc4a

Browse files
authored
Merge pull request #259 from nyu-mlab/pcap
Bug Fixes for IoT Inspector 3 Release
2 parents 86bca52 + 2911d6a commit 545bc4a

File tree

6 files changed

+380
-220
lines changed

6 files changed

+380
-220
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ authors = [
1616
{ name = "Danny Huang", email = "[email protected]" },
1717
{ name = "Andrew Quijano", email = "[email protected]" }
1818
]
19-
license = "MIT"
19+
license = "Apache-2.0"
2020
classifiers = [
2121
"Programming Language :: Python :: 3",
2222
"Operating System :: OS Independent",

src/libinspector/common.py

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import datetime
2-
import os
32
import time
43
import threading
54
import json
65
import functools
7-
import requests
86
import libinspector.global_state
97
from libinspector.privacy import is_ad_tracked
108
import pandas as pd
@@ -46,7 +44,7 @@ def show_warning():
4644
st.info(f"Your currently stored ID is: `{current_id}`")
4745

4846
# Allows the user to change the ID, which forces them back through GATE 1
49-
if st.button("Change Prolific ID"):
47+
if st.button("Change Prolific ID", help="Clicking this will clear your stored ID and return you to the ID entry form."):
5048
config_set("prolific_id", "") # Clear the stored ID
5149
st.rerun()
5250

@@ -55,7 +53,7 @@ def show_warning():
5553
st.subheader("2. Network Monitoring Warning")
5654
st.markdown(warning_text)
5755

58-
if st.button("OK, I understand and wish to proceed"):
56+
if st.button("OK, I understand and wish to proceed", help="Clicking this confirms that you understand the warning and wish to proceed."):
5957
config_set("suppress_warning", True)
6058
st.rerun()
6159

@@ -217,74 +215,6 @@ def get_remote_hostnames(mac_address: str):
217215
return remote_hostnames
218216

219217

220-
@st.cache_data(show_spinner=False)
221-
def call_predict_api(dhcp_hostname: str, oui_vendor: str, remote_hostnames: str,
222-
mac_address: str, url="https://dev-id-1.tailcedbd.ts.net/predict") -> dict:
223-
"""
224-
Call the predicting API with the given fields.
225-
This takes the MAC Address of an inspected device
226-
and checks the `devices` table, where iot inspector core collected meta-data
227-
based on SSDP discovery.
228-
Please see Page 11 Table A.1. We explain how to get the data from IoT Inspector:
229-
1. oui_friendly: we use the OUI database from IoT Inspector Core
230-
2. dhcp_hostname: this is extracted from the 'devices' table, check meta-data and look for 'dhcp_hostname' key.
231-
3. remote_hostnames: IoT Inspector collects this information the DHCP hostname via either DNS or SNI
232-
Args:
233-
dhcp_hostname (str): The DHCP hostname of the device we want to use AI to get more info about
234-
oui_vendor (str): The OUI vendor of the device we want to use AI to get more info about
235-
remote_hostnames (str): The remote hostnames the device has contacted
236-
mac_address (str): The MAC address of the device we want to use AI to get more info about
237-
url (str): The API endpoint.
238-
Returns:
239-
dict: The response text from the API.
240-
"""
241-
api_key = os.environ.get("API_KEY", "momo")
242-
device_tracked_key = f'tracked@{mac_address}'
243-
244-
headers = {
245-
"Content-Type": "application/json",
246-
"x-api-key": api_key
247-
}
248-
data = {
249-
"prolific_id": config_get("prolific_id", ""),
250-
"mac_address": mac_address,
251-
"fields": {
252-
"oui_friendly": oui_vendor,
253-
"dhcp_hostname": dhcp_hostname,
254-
"remote_hostnames": remote_hostnames,
255-
"user_agent_info": "",
256-
"netdisco_info": "",
257-
"user_labels": "",
258-
"talks_to_ads": config_get(device_tracked_key, False)
259-
}
260-
}
261-
non_empty_field_values = [
262-
field_value
263-
for field_name, field_value in data["fields"].items()
264-
if field_name != "talks_to_ads" and bool(field_value)
265-
]
266-
# TODO: We should make this 2 fields eventually...
267-
if len(non_empty_field_values) < 1:
268-
logger.warning(
269-
"[Device ID API] Fewer than two string fields in data are non-empty; refusing to call API. Wait until IoT Inspector collects more data.")
270-
raise RuntimeError(
271-
"Fewer than two string fields in data are non-empty; refusing to call API. Wait until IoT Inspector collects more data.")
272-
273-
logger.info("[Device ID API] Calling API with data: %s", json.dumps(data, indent=4))
274-
275-
try:
276-
response = requests.post(url, headers=headers, json=data, timeout=10)
277-
response.raise_for_status()
278-
result = response.json()
279-
except (requests.exceptions.RequestException, ValueError) as e:
280-
logger.error(f"[Device ID API] API request failed: {e}")
281-
raise RuntimeError("API request failed, not caching this result.")
282-
283-
logger.info("[Device ID API] API query successful!")
284-
config_set(f'device_details@{mac_address}', result)
285-
return result
286-
287-
288218
def get_human_readable_time(timestamp=None):
289219
"""
290220
Convert a timestamp to a human-readable time format.

0 commit comments

Comments
 (0)