Skip to content

v2.1.0 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/hlp/hlp_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ void print_hlp_info() {
print_banner();
printf("Spynix is a commandline tool for gathering info about hardware.\n\n \
Info:\n\t \
-h or --help - show this menu\n\t \
-v or --version - show version\n\t \
-b or --banner - show ASCII banner\n\n \
-h or --help \t- show this menu\n\t \
-v or --version \t- show version\n\t \
-b or --banner \t- show ASCII banner\n\n \
Options:\n\t \
-a or --all - show summary info about system, cpu, ram and rom\n\t \
-sys - show system info\n\t \
-cpu - show short Central Process Unit info\n\t \
-ram - show Random Access Memory info\n\t \
-rom - show Read Only Memory info\n\n \
-a or --all \t- show summary info about system, cpu, ram and rom\n\t \
-sys \t\t- show system info\n\t \
-cpu \t\t- show short Central Processing Unit info\n\t \
-ram \t\t- show Random Access Memory info\n\t \
-rom \t\t- show Read Only Memory info\n\t \
-net \t\t- show network info\n\n \
Advanced:\n\t \
-cpu -f or -cpu --full - show full Central Process Unit info\n");
-cpu -f or -cpu --full \t- show full Central Processing Unit info\n");
}

void print_ver_info() {
print_banner();
printf("spynix v2.0.0\n\nFor more info visit: https://github.com/git-user-cpp/spynix\n");
printf("spynix v2.1.0\n\nFor more info visit: https://github.com/git-user-cpp/spynix\n");
}
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "cpu/cpu_info.h"
#include "rom/rom_info.h"
#include "hlp/hlp_info.h"
#include "net/net_info.h"

int main(int argc, char **argv) {
if(argc == 1) {
Expand All @@ -27,6 +28,13 @@ int main(int argc, char **argv) {
print_ram_info();
} else if(strcmp(argv[1], "-rom") == 0) {
print_rom_info();
} else if(strcmp(argv[1], "-net") == 0) {
char host_name[100];
printf("Enter a hostname or IP address: ");
fgets(host_name, sizeof(host_name), stdin);
host_name[strcspn(host_name, "\n")] = '\0';

print_net_info(host_name);
} else if(strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
print_ver_info();
} else if(strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "--banner") == 0) {
Expand Down
36 changes: 36 additions & 0 deletions src/net/net_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <ifaddrs.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>

void print_net_info(char *hostname){
struct hostent *host = gethostbyname(hostname);
if(host == NULL){
perror("gethostbyname");
exit(1);
} else {
printf("Host Name: %s\n", host->h_name);
printf("IP Address: ");
for(int i = 0; host->h_addr_list[i] != NULL; i++){
printf("%s ", inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
}
printf("\n");
}

struct ifaddrs *ifaddr, *ifa;
if(getifaddrs(&ifaddr) == -1) {
perror("getifaddrs");
exit(1);
}
for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next){
if(ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_INET){
printf("Interface: %s\n", ifa->ifa_name);
printf("Address: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr));
printf("Netmask: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr));
}
}

freeifaddrs(ifaddr);
}