Skip to content
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

Fix OUI & Ports data #156

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,10 @@ This means that modifications need to be done either on a new branch based off o
This app does not track, collect, or share any data it comes across with anyone or anything.
There are no ads or analytics trackers in this software.
The service used to determine your public IP address is [open source](https://github.com/aaronjwood/public-ip-api) and is 100% stateless.

## Acknowledgements

MAC address vendor OUI resolution is possible thanks to the [lookup table](https://www.wireshark.org/download/automated/data/manuf) assembled by WireShark from IEEE public OUI listings.
See also [Wireshark's OUI Lookup Tool](https://www.wireshark.org/tools/oui-lookup.html).

Port service names and descriptions are provided by the IANA as the [Service Name and Transport Protocol Port Number Registry](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -95,18 +96,25 @@ final void doInBackground(String service, Parser parser) {
return;
}

in = new BufferedReader(new InputStreamReader(new GZIPInputStream(body.byteStream()), StandardCharsets.UTF_8));
String line;
InputStream bodyStream = body.byteStream();
boolean gzipped = "gzip".equals(response.header("Content-Encoding"));
if (gzipped) {
bodyStream = new GZIPInputStream(bodyStream);
}
in = new BufferedReader(new InputStreamReader(bodyStream, StandardCharsets.UTF_8));
// Lean on the fact that we're working with UTF-8 here.
// Also, make a rough estimation of how much we need to reduce this to account for the compressed data we've received.
double progressPerByte = 100d / body.contentLength() * (gzipped ? 3 : 1);
long total = 0;
String line;
while ((line = in.readLine()) != null) {
if (isCancelled()) {
return;
}

// Lean on the fact that we're working with UTF-8 here.
// Also, make a rough estimation of how much we need to reduce this to account for the compressed data we've received.
total += line.length() / 3;
downProg.progress = (int) (total * 100 / body.contentLength());
total += line.length();
downProg.progress = (int) (total * progressPerByte);

publishProgress(downProg);
String[] data = parser.parseLine(line);
if (data == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

public class DownloadOuisAsyncTask extends DownloadAsyncTask {

// The official source on gitlab.com doesn't provide a content length header which ruins our ability to report progress!
private static final String SERVICE = "https://raw.githubusercontent.com/wireshark/wireshark/master/manuf";
private static final String SERVICE = "https://www.wireshark.org/download/automated/data/manuf";

/**
* Creates a new asynchronous task to handle downloading OUI data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class DownloadPortDataAsyncTask extends DownloadAsyncTask {

// The official source on iana.org doesn't provide a content length header which ruins our ability to report progress!
private static final String SERVICE = "https://raw.githubusercontent.com/wireshark/wireshark/master/services";
private static final String SERVICE = "https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv";

/**
* Creates a new asynchronous task that takes care of downloading port data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public String[] parseLine(String line) {
}

String[] data = line.split("\\t");
String mac = data[0].toLowerCase();
String mac = data[0].trim().toLowerCase();
String vendor;
if (data.length == 3) {
vendor = data[2];
} else {
vendor = data[1];
vendor = data[1].trim();
}

return new String[]{mac, vendor};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
public class PortParser implements Parser {

/**
* Parses the line of port data based on IANA's format.
* Parses the line of the port data CSV file provided by IANA.
*
* @param line
* @return
*/
@Override
public String[] parseLine(String line) {
if (line.isEmpty() || line.startsWith("#")) {
if (line.isEmpty() || line.startsWith(" ") || line.startsWith(",")) {
return null;
}

String[] data = line.split("\\s+");
if (!data[1].contains("tcp")) {
String[] data = line.split(",");
if (data.length < 3 || !data[2].contains("tcp")) {
return null;
}

String port = data[1].substring(0, data[1].indexOf("/"));
String description = data[0];
if (line.contains("#")) {
description = line.substring(line.indexOf("#") + 1);
String port = data[1];
if (!port.matches("\\d+")){
return null;
}
String description = data.length >= 4 ? data[3] : data[0];

return new String[]{port, description};
}
Expand Down