Skip to content

Commit

Permalink
Merge pull request #7 from git-user-cpp/development
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
git-user-cpp authored Jan 13, 2024
2 parents dcb2956 + db44536 commit f994edd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
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);
}

0 comments on commit f994edd

Please sign in to comment.