Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * FreeBSD Info Program -- A Simple FreeBSD Information Program
- * Created by RAZ0REDGE
- * June. 2014
- *
- *
- */
- #include <sys/utsname.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <pwd.h>
- #include <time.h>
- #include <sys/sysctl.h>
- #include <sys/statvfs.h>
- #define C0 "\x1b[0m" //Reset
- #define C1 "\x1b[0;32m" //Green
- #define C2 "\x1b[0;31m" //Red
- #define C3 "\x1b[0;36m" //Cyan
- #define C4 "\x1b[0;35m" //Magenta
- #define CYN C3
- #define GRN C1
- #define NOR C0
- #define ANSI_COLOR_RED "\x1b[31m" // Another Example to show ANSI colours thanks vinnie01
- #define ANSI_COLOR_GREEN "\x1b[32m"
- #define ANSI_COLOR_YELLOW "\x1b[33m"
- #define ANSI_COLOR_BLUE "\x1b[34m"
- #define ANSI_COLOR_MAGENTA "\x1b[35m"
- #define ANSI_COLOR_CYAN "\x1b[36m"
- #define ANSI_COLOR_RESET "\x1b[0m"
- static const struct {
- const char *ctls;
- const char *names;
- } values[] = {
- { "hw.model", "CPU" },
- { "hw.memsize", "Memory" },
- { "kern.ostype", "OS" },
- { "kern.osrelease", "Kernel" },
- { "kern.hostname", "Hostname" },
- };
- static void sysctls(int i);
- static void disk(void);
- static void mem(void);
- // The help information. When you execute the program using finfo -h
- void help(void) {
- printf("╔════════════════════════════════════════════════╗\n"
- "║ FreeBSD Info --- By: RAZ0REDGE June. 2014 ║\n"
- "╚════════════════════════════════════════════════╝\n"
- "-h shows this help msg which isn't any help haha\n");
- exit(0);
- }
- // FreeBSD sysctl
- static void sysctls(int i) {
- size_t len;
- if(i==2) {
- // mem();
- } else {
- sysctlbyname(values[i].ctls, NULL, &len, NULL, 0);
- char *type = malloc(len);
- sysctlbyname(values[i].ctls, type, &len, NULL, 0);
- printf(GRN"\t\t\t║ %-10s╠═%s\n", values[i].names, type);
- free(type);
- }
- }
- // Disk usage in % of total disk size
- static void disk(void) { // Now works for FreeBSD & Darwin lulz took awhile to figured out :P
- struct statvfs info;
- if(!statvfs("/", &info)) {
- unsigned long left = (info.f_bfree * info.f_frsize);
- unsigned long total = (info.f_blocks * info.f_frsize);
- unsigned long used = total - left;
- float perc = (float)used / (float)total;
- printf(GRN"\t\t\t║ Disk ╠═%.2f%% of %.2f GB\n",
- perc * 100, (float)total / 1e+09);
- }
- }
- // Uptime Information by: yrmt <-- Still learning C I will redo this code once I get better.
- static void uptime(time_t *nowp) { // Thank you yrmt
- struct timeval boottime;
- time_t uptime;
- int days, hrs, mins, secs;
- int mib[2];
- size_t size;
- char buf[256];
- if(strftime(buf, sizeof(buf), NULL, localtime(nowp)))
- mib[0] = CTL_KERN;
- mib[1] = KERN_BOOTTIME;
- size = sizeof(boottime);
- if(sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
- boottime.tv_sec) {
- uptime = *nowp - boottime.tv_sec;
- if(uptime > 60)
- uptime += 30;
- days = (int)uptime / 86400;
- uptime %= 86400;
- hrs = (int)uptime / 3600;
- uptime %= 3600;
- mins = (int)uptime / 60;
- secs = uptime % 60;
- printf(C1"\t\t\t╔═══════════╗\n");
- printf(C1"\t\t\t║ System Up ╠═");
- if(days > 0)
- printf("%d day%s", days, days > 1? "s " : " ");
- if (hrs > 0 && mins > 0)
- printf("%02d:%02d", hrs, mins);
- else if(hrs == 0 && mins > 0)
- printf("0:%02d", mins);
- else
- printf("0:00");
- putchar('\n');
- }
- }
- int main(int argc, char **argv) { // Took me awhile to get this sorted with the help of Vincent0ne- cheers!
- if (argc >= 2) {
- int c;
- while ((c = getopt(argc, argv, "h")) != -1) {
- switch (c) {
- case 'h':
- default:
- help();
- break;
- }
- }
- }
- // My Epic FreeBSD logo that I done in blocks and bars. Cyberpunk still exist in UNIX
- time_t now;
- time(&now);
- uptime(&now);
- printf(C1"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀\n");
- printf(C2" ▄████████ ▄████████ ▄████████ ▄████████ ▀█████████▄ ████████ ████████▄\n");
- printf(C2" ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀███\n");
- printf(C2" ███ █▀ ███ ███ ███ █▀ ███ █▀ ███ ███ ███ █▀ ███ ███\n");
- printf(C2" ▄███▄▄▄ ▄███▄▄▄▄██▀ ▄███▄▄▄ ▄███▄▄▄ ▄███▄▄▄██▀ ███ ███ ███\n");
- printf(C2"▀▀███▀▀▀ ▀▀███▀▀▀▀▀ ▀▀███▀▀▀ ▀▀███▀▀▀ ▀▀███▀▀▀██▄ ▀███████████ ███ ███\n");
- printf(C2" ███ ▀███████████ ███ █▄ ███ █▄ ███ ██▄ ███ ███ ███\n");
- printf(C2" ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄█ ███ ███ ▄███\n");
- printf(C2" ███ ███ ███ ██████████ ██████████ ▄█████████▀ ▄████████▀ ████████▀ \n");
- printf(C1"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀");printf(C2"███");printf(C1"▀▀▀▀");printf(C2"███");printf(C1"▀▀▀▀▀▀▀▀▀▀▀");printf(C2"██");printf(C1"▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀\n"C0);
- // This is a Mixure of the information Output for most. 1. utsname & 2. sysctl. To give 2 examples just for fun.
- {
- char computer[256];
- struct utsname uts;
- time_t timeval;
- (void)time(&timeval);
- if(gethostname(computer, 255) != 0 || uname(&uts) < 0) {
- fprintf(stderr, "Could not get host information, so fuck off\n"); // Lulz very funny Vincent0ne-
- exit(1);
- }
- printf(ANSI_COLOR_GREEN"\t\t\t║ User ╠═%s\n", getlogin()); // Another example to show info thanks vinnie01
- printf(ANSI_COLOR_GREEN"\t\t\t║ Date ╠═%s", ctime(&timeval));
- printf(ANSI_COLOR_GREEN"\t\t\t║ Hostname ╠═%s\n", computer);
- printf(ANSI_COLOR_GREEN"\t\t\t║ OS ╠═%s\n", uts.sysname);
- printf(ANSI_COLOR_GREEN"\t\t\t║ Version ╠═%s\n", uts.release);
- printf(ANSI_COLOR_GREEN"\t\t\t║ Hardware ╠═%s\n", uts.machine);
- sysctls(0); // Shows CPU Model or System Model in Darwin
- disk(); // Using statvfs interesting how it works much like df.
- printf(ANSI_COLOR_GREEN"\t\t\t╚═══════════╝\n");
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement