Skip to content

Commit

Permalink
Add network info
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Jonas committed Feb 27, 2016
1 parent 2868c3f commit 1ca986f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -69,12 +69,13 @@ Get quickly infos about the operating system, the current system and the current

##Changelog

### 1.2 - PLANED
### 1.2 - SCHEDULED
- Implement FONT-AWESOME Icon Lib

### 1.1.1
- Add Wiki Infos and Tutorials
- Add Logo
- Add ipv4 and ipv6 to system info

### 1.1
- First release on maven
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/de/jonato/jfxc/info/CurrentSystem.java
Expand Up @@ -20,6 +20,9 @@
* #L%
*/

import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -58,6 +61,54 @@ public String get() {
private static String javaVersion;
private static String fileSeparator;
private static String javaHome;
private static String ipv4;
private static String ipv6;
private static String hostname;

/**
* Get the hostname of the machine.
* @return current hostname.
*/
public static String getHostname(){
if(hostname == null) {
try {
hostname = Inet4Address.getLocalHost().getHostName();
} catch (UnknownHostException e) {
hostname = "unknown";
}
}
return hostname;
}

/**
* Get the ipv4 address of the machine.
* @return current lan ip address
*/
public static String getIPv4Adress(){
if(ipv4 == null) {
try {
ipv4 = Inet4Address.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
ipv4 = "unknown";
}
}
return ipv4;
}

/**
* Get the ipv6 address of the machine.
* @return current lan ipv6 address
*/
public static String getIPv6Adress(){
if(ipv6 == null) {
try {
ipv6 = Inet6Address.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
ipv6 = "unknown";
}
}
return ipv6;
}

/**
* Get java version from system property.
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/de/jonato/jfxc/info/CurrentSystemTest.java
Expand Up @@ -52,6 +52,9 @@ public void testSystemInfo() {
assertTrue(
CurrentSystem.getJavaHome().length() > 0 &&
CurrentSystem.getJavaVersion().length() > 0 &&
CurrentSystem.getIPv4Adress().length() > 0 &&
CurrentSystem.getIPv6Adress().length() > 0 &&
CurrentSystem.getHostname().length() > 0 &&
CurrentSystem.getSeparator().length() > 0
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/de/jonato/jfxc/samples/InfoGen.java
Expand Up @@ -35,6 +35,10 @@ public static void main(String[] args) {
System.out.println("JAVA Home: " + CurrentSystem.getJavaHome());
System.out.println("JAVA Version: " + CurrentSystem.getJavaVersion());

System.out.println("IPv4: " + CurrentSystem.getIPv4Adress());
System.out.println("IPv6: " + CurrentSystem.getIPv6Adress());
System.out.println("Hostname: " + CurrentSystem.getHostname());

System.out.println("OS: " + OS.getOsName());
System.out.println("Version: " + OS.getVersion());

Expand Down

0 comments on commit 1ca986f

Please sign in to comment.