/
MACVendorFetcher.java
52 lines (44 loc) · 1.31 KB
/
MACVendorFetcher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package net.azib.ipscan.fetchers;
import net.azib.ipscan.core.ScanningSubject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class MACVendorFetcher extends AbstractFetcher {
public static final String ID = "fetcher.mac.vendor";
private static Map<String, String> vendors = new HashMap<>();
private MACFetcher macFetcher;
public MACVendorFetcher(MACFetcher macFetcher) {
this.macFetcher = macFetcher;
}
@Override
public String getId() {
return ID;
}
@Override
public void init() {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/mac-vendors.txt")))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.isEmpty()) continue;
vendors.put(line.substring(0, 6), line.substring(6));
}
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public Object scan(ScanningSubject subject) {
String mac = (String)subject.getParameter(MACFetcher.ID);
if (mac == null) {
macFetcher.scan(subject);
mac = (String) subject.getParameter(MACFetcher.ID);
}
return mac != null ? findMACVendor(mac) : null;
}
String findMACVendor(String mac) {
return vendors.get(mac.replace(":", "").substring(0, 6));
}
}