File tree Expand file tree Collapse file tree 4 files changed +21
-2
lines changed
src/main/java/xyz/e3ndr/jeofetch Expand file tree Collapse file tree 4 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public class Jeofetch {
3131 USERNAME = System .getProperty ("user.name" , "user" );
3232
3333 try {
34- HOSTNAME = InetAddress . getLocalHost ().getHostName ();
34+ HOSTNAME = SystemUtils . getSystemHandler ().getHostname ();
3535 } catch (UnknownHostException e ) {
3636 HOSTNAME = "localhost" ;
3737 }
Original file line number Diff line number Diff line change 22
33import java .io .IOException ;
44
5+ import lombok .Getter ;
56import xyz .e3ndr .jeofetch .system .ISystem ;
67import xyz .e3ndr .jeofetch .system .MacOSSystem ;
78import xyz .e3ndr .jeofetch .system .UnixSystem ;
1213
1314public class SystemUtils {
1415 private static UnknownSystem unknownSystemHandler = new UnknownSystem ();
15- private static ISystem systemHandler ;
16+ private static @ Getter ISystem systemHandler ;
1617
1718 static {
1819 String name = System .getProperty ("os.name" , "" ).toLowerCase ();
Original file line number Diff line number Diff line change 11package xyz .e3ndr .jeofetch .system ;
22
33import java .io .IOException ;
4+ import java .net .InetAddress ;
5+ import java .net .UnknownHostException ;
46
57import xyz .e3ndr .jeofetch .types .CpuInfo ;
68
@@ -13,5 +15,9 @@ public interface ISystem {
1315 public String getOsName () throws IOException ;
1416
1517 public String getVersion () throws IOException ;
18+
19+ default String getHostname () throws UnknownHostException {
20+ return InetAddress .getLocalHost ().getHostName ();
21+ }
1622
1723}
Original file line number Diff line number Diff line change 22
33import java .io .IOException ;
44import java .io .InputStream ;
5+ import java .net .InetAddress ;
6+ import java .net .UnknownHostException ;
57import java .nio .charset .StandardCharsets ;
68import java .util .ArrayList ;
79import java .util .List ;
@@ -33,6 +35,16 @@ public String getOsName() throws IOException {
3335 return System .getProperty ("os.name" , "Unknown" );
3436 }
3537
38+ public String getHostname () throws UnknownHostException {
39+ String hostname = InetAddress .getLocalHost ().getHostName ();
40+
41+ if (hostname .endsWith (".local" )) {
42+ return hostname .substring (0 , hostname .length () - ".local" .length ());
43+ } else {
44+ return hostname ;
45+ }
46+ }
47+
3648 private static CpuInfo getCpuInfo_sysctl () throws IOException {
3749 String [] sysctl = IOUtil .readInputStreamString (Runtime .getRuntime ().exec ("sysctl -a" ).getInputStream (), StandardCharsets .UTF_8 ).split ("\n " );
3850
You can’t perform that action at this time.
0 commit comments