Classify supplied synthetic device traffic patterns
Tune a transparent camera-candidate classifier on synthetic packet metadata and score unseen traces with false positives visible.

Radio Remi
Radio Remi: predict first, inspect every intermediate value, and keep the claim inside the evidence.
Predict the reading, then compare it with the measurement.
Python 3 in your browser (JupyterLite)
Python · no installOpen the notebook in your browser and run each Python cell; no install or account is needed.
Three ways to run: use JupyterLite here with no install; run main.py locally from the downloadable lab folder; or open the same notebook in Google Colab.
Steps
Step 1
- Do
- In the JupyterLite notebook, run the Step 1 cell to predict how a camera, phone, and smart plug might differ.
- You will see
Run the cell. You should see:
- seed=437; classes=camera, phone, smart-plug
- 32 synthetic packets per trace; 8 traces per class
- No live packets, payloads, MAC addresses, or target network.
- Why it matters
- Expected: the seeded fixture creates three metadata classes with eight traces each. The code run reports seed 437 and 32 packets per trace. This fixes a reproducible synthetic comparison before classification. Limit: there are no live packets or device identities.
Code for step 1import platform import pyodide print(f"Runtime: Python {platform.python_version()} / Pyodide {pyodide.__version__}") """Classify generated packet metadata; no payload, address, or live network capture.""" import argparse import random import statistics SEED = 437 CLASSES = ('camera', 'phone', 'smart-plug') def make_trace(kind, seed): rng = random.Random(seed) count = 32 if kind == 'camera': sizes = [max(64, int(rng.gauss(1050, 120))) for _ in range(count)] gaps = [max(0.01, rng.gauss(0.12, 0.025)) for _ in range(count)] uplink = [rng.random() < 0.9 for _ in range(count)] elif kind == 'phone': sizes = [max(64, int(rng.gauss(600 if i % 5 else 1100, 270))) for i in range(count)] gaps = [rng.uniform(0.05, 0.8) for _ in range(count)] uplink = [rng.random() < 0.55 for _ in range(count)] else: sizes = [max(40, int(rng.gauss(115, 25))) for _ in range(count)] gaps = [max(0.1, rng.gauss(3.0, 0.3)) for _ in range(count)] uplink = [rng.random() < 0.65 for _ in range(count)] return {'kind': kind, 'sizes': sizes, 'gaps': gaps, 'uplink': uplink} def features(trace): return (statistics.median(trace['sizes']), statistics.pstdev(trace['gaps']) / statistics.mean(trace['gaps']), sum(trace['uplink']) / len(trace['uplink'])) def classify(trace, size_floor=800, uplink_floor=0.75): size, gap_cv, uplink = features(trace) if size < 250: return 'smart-plug' if size >= size_floor and uplink >= uplink_floor and gap_cv < 0.5: return 'camera' return 'phone' def fixtures(offset=0): return [make_trace(kind, SEED + offset + row * 37 + class_index * 1000) for class_index, kind in enumerate(CLASSES) for row in range(8)] def score(rows, floor=800): predictions = [(row['kind'], classify(row, size_floor=floor)) for row in rows] tp = sum(actual == predicted == 'camera' for actual, predicted in predictions) fp = sum(actual != 'camera' and predicted == 'camera' for actual, predicted in predictions) fn = sum(actual == 'camera' and predicted != 'camera' for actual, predicted in predictions) return tp, fp, fn, tp / (tp + fp or 1), tp / (tp + fn or 1) def step_1(): return ['STEP 1 | predict before classification', 'Predict: streaming camera has larger regular uplink bursts.', f'seed={SEED}; classes={", ".join(CLASSES)}', '32 synthetic packets per trace; 8 traces per class', 'No live packets, payloads, MAC addresses, or target network.'] lines = step_1() assert 4 <= len(lines) <= 15 print("\n".join(lines))
Step 1 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 2
- Do
- In the JupyterLite notebook, run the Step 2 cell to generate packet sizes and time gaps for each class.
- You will see
Run the cell. You should see:
- camera [996, 1039, 1068] [0.11, 0.15, 0.15]
- phone [1197, 1059, 203] [0.51, 0.73, 0.68]
- smart-plug [71, 113, 85] [2.76, 3.6, 3.15]
- Why it matters
- Expected: generated classes have distinct packet-size and timing patterns. These first three sizes and gaps are the exact seed-437 run output. The displayed cues are available from metadata alone in this fixture. Limit: generated distributions do not establish real device behavior.
Code for step 2def step_2(): rows = [] for i, kind in enumerate(CLASSES): sample = make_trace(kind, SEED + i * 1000) rows.append(f'{kind:<10} {str(sample["sizes"][:3]):<22} {[round(x, 2) for x in sample["gaps"][:3]]}') return ['STEP 2 | generate the metadata', 'class first sizes (bytes) first gaps (seconds)', *rows, 'Values are generated with stated class-specific distributions.'] lines = step_2() assert 4 <= len(lines) <= 15 print("\n".join(lines))
Step 2 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 3
- Do
- In the JupyterLite notebook, run the Step 3 cell to calculate median size, gap variation, and uplink share.
- You will see
Run the cell. You should see:
- camera 1019 0.19 0.94
- phone 664 0.53 0.59
- smart-plug 111 0.09 0.62
- Why it matters
- Expected: camera, phone, and smart-plug fixtures differ in median size, gap CV, and uplink share. The run printed the three feature rows shown at left. These are transparent decision inputs for the later threshold rule. Limit: feature separation here is not a device fingerprint guarantee.
Code for step 3def step_3(): return ['STEP 3 | compute transparent features', 'class median bytes gap CV uplink share', *[f'{kind:<10} {features(make_trace(kind,SEED+i*1000))[0]:>7.0f} {features(make_trace(kind,SEED+i*1000))[1]:.2f} {features(make_trace(kind,SEED+i*1000))[2]:.2f}' for i, kind in enumerate(CLASSES)], 'CV = standard deviation of gaps / mean gap.'] lines = step_3() assert 4 <= len(lines) <= 15 print("\n".join(lines))
Step 3 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 4
- Do
- In the JupyterLite notebook, run the Step 4 cell to tune one size threshold using training traces only.
- You will see
Run the cell. You should see:
- floor=650 bytes: TP=8 FP=0 FN=0
- floor=800 bytes: TP=8 FP=0 FN=0
- floor=950 bytes: TP=8 FP=0 FN=0
- Why it matters
- Expected: training fixtures show the trade-off for each tested size floor. All three floors classify 8 camera traces with zero training FP or FN. The notebook chooses 800 bytes before opening the held-out fixture. Limit: tuning and scoring still use synthetic generated traces.
Code for step 4def step_4(): train = fixtures() return ['STEP 4 | tune one camera threshold on training traces', 'rule: median size ≥ floor, uplink share ≥ 0.75, gap CV < 0.50', *[f'floor={floor} bytes: TP={score(train,floor)[0]} FP={score(train,floor)[1]} FN={score(train,floor)[2]}' for floor in (650, 800, 950)], 'Choose 800 bytes before opening the held-out fixture.'] lines = step_4() assert 4 <= len(lines) <= 15 print("\n".join(lines))
Step 4 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 5
- Do
- In the JupyterLite notebook, run the Step 5 cell to score the chosen rule on held-out synthetic traces.
- You will see
Run the cell. You should see:
- camera TP=8; FP=0; FN=0
- precision=1.000; recall=1.000
- held-out traces=24; seed offset=90000
- Why it matters
- Expected: the held-out fixture contains 24 traces and prints its classification counts. The run reports eight true positives and no FP or FN. Precision and recall are both 1.000 for these generated traces. Limit: this score is not real-room device identification.
Code for step 5def step_5(): tp, fp, fn, precision, recall = score(fixtures(90_000)) return ['STEP 5 | score unseen synthetic traces', f'camera TP={tp}; FP={fp}; FN={fn}', f'precision={precision:.3f}; recall={recall:.3f}', f'held-out traces={len(fixtures(90_000))}; seed offset=90000', 'A fixture score is not device identification in a real room.'] lines = step_5() assert 4 <= len(lines) <= 15 print("\n".join(lines))
Step 5 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 6
- Do
- In the JupyterLite notebook, run the Step 6 cell to stress an upload-heavy phone case.
- You will see
Run the cell. You should see:
- altered median=1209 bytes
- altered uplink share=1.00
- prediction=camera; true class=phone
- Why it matters
- Expected: upload-heavy phone metadata may cross the camera thresholds. The stress case predicts camera for the altered phone fixture. This demonstrates a false-positive mode under shifted traffic. Limit: any real decision needs independent authorized checks.
Code for step 6def step_6(): altered = make_trace('phone', SEED + 55000) altered['sizes'] = [size + 500 for size in altered['sizes']] altered['gaps'] = [0.12 + 0.01 * (i % 3) for i in range(len(altered['gaps']))] altered['uplink'] = [True] * len(altered['uplink']) return ['STEP 6 | stress an upload-heavy phone', f'altered median={features(altered)[0]:.0f} bytes', f'altered uplink share={features(altered)[2]:.2f}', f'prediction={classify(altered)}; true class=phone', 'False positives need independent authorised checks.'] lines = step_6() assert 4 <= len(lines) <= 15 print("\n".join(lines))
Step 6 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Step 7
- Do
- In the JupyterLite notebook, run the Step 7 cell to write a candidate and lawful-use result card.
- You will see
Run the cell. You should see:
- method=size + gap CV + uplink thresholds; held-out precision=1.00
- held-out recall=1.00; false positives=0; false negatives=0
- decision=record candidate and seek independent authorised confirmation
- Why it matters
- Expected: the result card summarizes the fixture metrics and its boundary. The executed score is perfect on this held-out synthetic set. The result supports a candidate pattern for further authorized review. Limit: no real device or lawful capture was tested.
Code for step 7def step_7(): tp, fp, fn, precision, recall = score(fixtures(90_000)) return ['STEP 7 | RESULT CARD', f'method=size + gap CV + uplink thresholds; held-out precision={precision:.2f}', f'held-out recall={recall:.2f}; false positives={fp}; false negatives={fn}', 'stress=upload-heavy phone can look camera-like', 'boundary=synthetic metadata; no real device or lawful capture tested', 'decision=record candidate and seek independent authorised confirmation'] lines = step_7() assert 4 <= len(lines) <= 15 print("\n".join(lines))
Step 7 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
What does a camera-like traffic classification establish?
Return to the chapter’s knowledge checkWhy combine RF and optical checks during an authorised inspection?
Return to the chapter’s knowledge check
Caution
Before you start
Read this before you start.
These generated fixtures prove calculations only. Reopen the prepared notebook if screens change; measured hardware, consent, and site evidence are required for a deployment claim.
Technical details
- Version tested
- Version tested: Python 3.12.7 / Pyodide 0.27.6 in JupyterLite 0.6.4; captureSource playwright:jupyterlite. Date: 2026-09-22.
- Fixture and seed
- Each notebook step runs with its stated deterministic fixture.
https://iotclass.org/labs/rogue-device-traffic-classifier.htmlReturn to Detecting Hidden Cameras and Rogue Devices · Browse Labs