-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfetch.java
71 lines (61 loc) · 2.58 KB
/
fetch.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class SystemInfo {
public static void main(String[] args) {
display();
}
public static void display() {
System.out.println("(\\_/)\t\u001B[0;33m uptime: " + uptime() + "\u001B[0;0m"); // uptime - orange
System.out.println("(oᴥo)\t\u001B[0;31m shell: " + shell() + "\u001B[0;0m"); // shell - red
System.out.println("|U°U|\t\u001B[0;35m distro: " + distro() + "\u001B[0;0m"); // distro - purple
System.out.println("| |\t\u001B[0;34m hostname: " + hostname() + "\u001B[0;0m"); // host - blue
System.out.println("'U_U'\t\u001B[0;36m kernel: " + kernel() + "\u001B[0;0m"); // kernel - cyan
System.out.println(" U");
}
public static String shell() {
return System.getenv("SHELL");
}
public static String uptime() {
try {
BufferedReader reader = new BufferedReader(new FileReader("/proc/uptime"));
String line = reader.readLine();
reader.close();
String[] parts = line.split(" ");
double uptimeSeconds = Double.parseDouble(parts[0]);
int days = (int) uptimeSeconds / 86400;
int hours = (int) (uptimeSeconds % 86400) / 3600;
int minutes = (int) (uptimeSeconds % 3600) / 60;
int seconds = (int) uptimeSeconds % 60;
int milliseconds = (int) ((uptimeSeconds - Math.floor(uptimeSeconds)) * 1000);
return String.format("%d Days, %dh %dm %ds.%d", days, hours, minutes, seconds, milliseconds);
} catch (IOException e) {
e.printStackTrace();
return "";
}
}
public static String distro() {
try {
BufferedReader reader = new BufferedReader(new FileReader("/etc/issue"));
String distro = reader.readLine();
reader.close();
return distro.replace("\\n", "").replace("\\l", "").replace("\\r", "").replace("()", ""); // Somehow the file contains certain characters in certain distros.
} catch (IOException e) {
e.printStackTrace();
return "";
}
}
public static String hostname() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
e.printStackTrace();
return "";
}
}
public static String kernel() {
return System.getProperty("os.name") + " " + System.getProperty("os.version");
}
}