-
Notifications
You must be signed in to change notification settings - Fork 0
Load drone OUIs from asset #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nbschultz97
wants to merge
5
commits into
main
Choose a base branch
from
codex/create-and-load-drone-oui-assets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25c067c
Add offline drone OUI database and loader
nbschultz97 d32026c
Ensure newline in OUI asset and update script
nbschultz97 52a6e01
Merge pull request #11 from nbschultz97/codex/fix-comments-le0yug
nbschultz97 9256d9c
Normalize OUIs to match detector format
nbschultz97 f7a0952
Merge pull request #14 from nbschultz97/codex/fix-comments-in-update_…
nbschultz97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # Generated binary assets | ||
| app/ | ||
| # Generated binary assets and build outputs | ||
| app/build/ | ||
| app/src/main/assets/ | ||
| app/src/main/res/ | ||
|
|
||
| __pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/vantagescanner/DroneSignalDetector.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.vantagescanner | ||
|
|
||
| import android.content.Context | ||
| import org.json.JSONArray | ||
| import java.io.BufferedReader | ||
| import java.util.Locale | ||
|
|
||
| /** | ||
| * Detects drone Wi-Fi signals by comparing MAC prefixes against a | ||
| * locally maintained list of Organizationally Unique Identifiers. | ||
| * | ||
| * OUI prefixes are loaded from the `drone_ouis.json` asset at runtime | ||
| * to avoid hard-coding vendor data. | ||
| */ | ||
| class DroneSignalDetector(private val context: Context) { | ||
| private val droneOuis: Set<String> by lazy { loadOuis() } | ||
|
|
||
| private fun loadOuis(): Set<String> { | ||
| context.assets.open("drone_ouis.json").use { input -> | ||
| val text = input.bufferedReader().use(BufferedReader::readText) | ||
| val arr = JSONArray(text) | ||
| val set = mutableSetOf<String>() | ||
| for (i in 0 until arr.length()) { | ||
| set += arr.getString(i).uppercase(Locale.US) | ||
| } | ||
| return set | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the MAC address belongs to a known drone vendor. | ||
| */ | ||
| fun isDrone(macAddress: String): Boolean { | ||
| val prefix = macAddress.uppercase(Locale.US).replace(":", "").take(6) | ||
| return prefix in droneOuis | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [ | ||
| "00121C", | ||
| "00267E", | ||
| "04A85A", | ||
| "0C9AE6", | ||
| "34D262", | ||
| "381D14", | ||
| "481CB9", | ||
| "58B858", | ||
| "60601F", | ||
| "8C5823", | ||
| "9003B7", | ||
| "903AE6", | ||
| "9C5A8A", | ||
| "A0143D", | ||
| "E47A2C" | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/usr/bin/env python3 | ||
| """Generate assets/drone_ouis.json from an IEEE OUI CSV. | ||
|
|
||
| The IEEE registry file `oui.csv` can be downloaded separately and stored | ||
| locally for offline use. This script extracts OUI prefixes for known drone | ||
| vendors and writes them to a JSON asset. | ||
| """ | ||
| import argparse | ||
| import csv | ||
| import json | ||
| from pathlib import Path | ||
| from typing import List | ||
|
|
||
| # Keywords identifying drone manufacturers in the IEEE registry | ||
| DRONE_KEYWORDS = ["DJI", "PARROT", "SKYDIO"] | ||
|
|
||
| ROOT = Path(__file__).resolve().parent.parent | ||
| ASSET_PATH = ROOT / "assets" / "drone_ouis.json" | ||
|
|
||
|
|
||
| def extract_ouis(csv_path: Path) -> List[str]: | ||
| ouis: set[str] = set() | ||
| with csv_path.open(newline="") as fh: | ||
| reader = csv.DictReader(fh) | ||
| for row in reader: | ||
| name = row.get("Organization Name", "").upper() | ||
| for key in DRONE_KEYWORDS: | ||
| if key in name: | ||
| ouis.add(row["Assignment"].upper()) | ||
| break | ||
| return sorted(ouis) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument( | ||
| "csv", nargs="?", default="oui.csv", help="Path to downloaded oui.csv" | ||
| ) | ||
| parser.add_argument( | ||
| "-o", | ||
| "--output", | ||
| default=str(ASSET_PATH), | ||
| help="Destination JSON asset (default: assets/drone_ouis.json)", | ||
| ) | ||
| args = parser.parse_args() | ||
| csv_path = Path(args.csv) | ||
| ouis = extract_ouis(csv_path) | ||
| out_path = Path(args.output) | ||
| out_path.parent.mkdir(parents=True, exist_ok=True) | ||
| out_path.write_text(json.dumps(ouis, indent=2) + "\n") | ||
| print(f"wrote {len(ouis)} OUIs -> {out_path}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.