diff --git a/src/hlp/hlp_info.h b/src/hlp/hlp_info.h index 4dd8db2..41e7591 100644 --- a/src/hlp/hlp_info.h +++ b/src/hlp/hlp_info.h @@ -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"); } diff --git a/src/main.c b/src/main.c index 899880b..3f33612 100644 --- a/src/main.c +++ b/src/main.c @@ -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) { @@ -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) { diff --git a/src/net/net_info.h b/src/net/net_info.h new file mode 100644 index 0000000..2802bc4 --- /dev/null +++ b/src/net/net_info.h @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +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); +}