Created
May 13, 2016 17:02
-
-
Save ningthoujam-lokhendro/eb860abfa884d9ed594385ca8c399075 to your computer and use it in GitHub Desktop.
Generate IEEE OUI in JSON format with java.
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
package com.ningzeta; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import com.fasterxml.jackson.databind.SerializationFeature; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.util.HashMap; | |
import java.util.Scanner; | |
public class App | |
{ | |
private static String OUI_URL = "http://standards-oui.ieee.org/oui/oui.txt"; | |
public void readOUI() { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
objectMapper.enable(SerializationFeature.INDENT_OUTPUT); | |
HashMap<String,OUI> ouiMap = new HashMap<>(); | |
try { | |
URL ouiURL = new URL(OUI_URL); | |
Scanner scanner = new Scanner(ouiURL.openStream()); | |
while (scanner.hasNextLine()){ | |
String line = scanner.nextLine(); | |
if(line.contains("(hex)")) { | |
String[] splits = line.split("\\(hex\\)"); | |
ouiMap.put(splits[0].trim(),new OUI(splits[1].trim())); | |
} | |
} | |
objectMapper.writeValue(new File("oui.json"),ouiMap); | |
} | |
catch (IOException ex) { | |
ex.printStackTrace(); | |
} | |
} | |
} |
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
package com.ningzeta; | |
/** | |
* OUI Definition class. | |
* | |
* @author Ningthoujam Lokhendro | |
* @since 5/11/2016 | |
*/ | |
public class OUI { | |
String vendor; | |
public OUI(String vendor) { | |
this.vendor = vendor; | |
} | |
public String getVendor() { | |
return vendor; | |
} | |
public void setVendor(String vendor) { | |
this.vendor = vendor; | |
} | |
} |
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
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.ningzeta</groupId> | |
<artifactId>oui</artifactId> | |
<packaging>jar</packaging> | |
<version>1.0.0-SNAPSHOT</version> | |
<name>oui</name> | |
<url>http://maven.apache.org</url> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<java.version>1.7</java.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-databind</artifactId> | |
<version>2.6.4</version> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.1</version> | |
<configuration> | |
<source>${java.version}</source> | |
<target>${java.version}</target> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment