Skip to content

Instantly share code, notes, and snippets.

@SatyaSnehith
Last active May 4, 2020 11:26
Show Gist options
  • Save SatyaSnehith/f6e7ed3f3ee010122aaa042c1bec1d5b to your computer and use it in GitHub Desktop.
Save SatyaSnehith/f6e7ed3f3ee010122aaa042c1bec1d5b to your computer and use it in GitHub Desktop.
Get organization name from mac address prefix. compile and run "java ListFile <mac address prefix(multiple)>. file:https://drive.google.com/file/d/16a1oCASZcM6NUU7t2dVKYFYi4D9_kvKY/view?usp=sharing
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class ListFile {
String fileName = "address_book.txt";
List<String> list;
ListFile() {
try {
Path path = Paths.get(fileName);
list = Files.readAllLines(path);
} catch (Exception e) {
e.printStackTrace();
}
}
int getSize() {
return list.size();
}
String getAddr(int index) {
return list.get(index).substring(0, 6);
}
String getOrgName(int index) {
String name = "[NO MATCHES]";
if(index > 0)
name = list.get(index).substring(11);
return name;
}
int find(String x) {
int low = 0;
int high = list.size() - 1;
int mid;
while (low <= high) {
mid = (low + high) / 2;
if (getAddr(mid).compareTo(x) < 0) {
low = mid + 1;
} else if (getAddr(mid).compareTo(x) > 0) {
high = mid - 1;
} else {
return mid;
}
}
return -1;
}
int stringCompare(String str1, String str2) {
int l1 = str1.length();
int l2 = str2.length();
int lmin = Math.min(l1, l2);
for (int i = 0; i < lmin; i++) {
int str1_ch = (int)str1.charAt(i);
int str2_ch = (int)str2.charAt(i);
if (str1_ch != str2_ch) {
return str1_ch - str2_ch;
}
}
if (l1 != l2)
return l1 - l2;
else
return 0;
}
public static void main(String[] args) {
ListFile lf = new ListFile();
for(String addr: args)
System.out.println(lf.getOrgName(lf.find(addr)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment