Skip to content

Commit f994edd

Browse files
authored
Merge pull request #7 from git-user-cpp/development
v2.1.0
2 parents dcb2956 + db44536 commit f994edd

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

src/hlp/hlp_info.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ void print_hlp_info() {
1818
print_banner();
1919
printf("Spynix is a commandline tool for gathering info about hardware.\n\n \
2020
Info:\n\t \
21-
-h or --help - show this menu\n\t \
22-
-v or --version - show version\n\t \
23-
-b or --banner - show ASCII banner\n\n \
21+
-h or --help \t- show this menu\n\t \
22+
-v or --version \t- show version\n\t \
23+
-b or --banner \t- show ASCII banner\n\n \
2424
Options:\n\t \
25-
-a or --all - show summary info about system, cpu, ram and rom\n\t \
26-
-sys - show system info\n\t \
27-
-cpu - show short Central Process Unit info\n\t \
28-
-ram - show Random Access Memory info\n\t \
29-
-rom - show Read Only Memory info\n\n \
25+
-a or --all \t- show summary info about system, cpu, ram and rom\n\t \
26+
-sys \t\t- show system info\n\t \
27+
-cpu \t\t- show short Central Processing Unit info\n\t \
28+
-ram \t\t- show Random Access Memory info\n\t \
29+
-rom \t\t- show Read Only Memory info\n\t \
30+
-net \t\t- show network info\n\n \
3031
Advanced:\n\t \
31-
-cpu -f or -cpu --full - show full Central Process Unit info\n");
32+
-cpu -f or -cpu --full \t- show full Central Processing Unit info\n");
3233
}
3334

3435
void print_ver_info() {
3536
print_banner();
36-
printf("spynix v2.0.0\n\nFor more info visit: https://github.com/git-user-cpp/spynix\n");
37+
printf("spynix v2.1.0\n\nFor more info visit: https://github.com/git-user-cpp/spynix\n");
3738
}

src/main.c

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "cpu/cpu_info.h"
55
#include "rom/rom_info.h"
66
#include "hlp/hlp_info.h"
7+
#include "net/net_info.h"
78

89
int main(int argc, char **argv) {
910
if(argc == 1) {
@@ -27,6 +28,13 @@ int main(int argc, char **argv) {
2728
print_ram_info();
2829
} else if(strcmp(argv[1], "-rom") == 0) {
2930
print_rom_info();
31+
} else if(strcmp(argv[1], "-net") == 0) {
32+
char host_name[100];
33+
printf("Enter a hostname or IP address: ");
34+
fgets(host_name, sizeof(host_name), stdin);
35+
host_name[strcspn(host_name, "\n")] = '\0';
36+
37+
print_net_info(host_name);
3038
} else if(strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
3139
print_ver_info();
3240
} else if(strcmp(argv[1], "-b") == 0 || strcmp(argv[1], "--banner") == 0) {

src/net/net_info.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <ifaddrs.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <sys/socket.h>
5+
#include <netdb.h>
6+
#include <arpa/inet.h>
7+
8+
void print_net_info(char *hostname){
9+
struct hostent *host = gethostbyname(hostname);
10+
if(host == NULL){
11+
perror("gethostbyname");
12+
exit(1);
13+
} else {
14+
printf("Host Name: %s\n", host->h_name);
15+
printf("IP Address: ");
16+
for(int i = 0; host->h_addr_list[i] != NULL; i++){
17+
printf("%s ", inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
18+
}
19+
printf("\n");
20+
}
21+
22+
struct ifaddrs *ifaddr, *ifa;
23+
if(getifaddrs(&ifaddr) == -1) {
24+
perror("getifaddrs");
25+
exit(1);
26+
}
27+
for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next){
28+
if(ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_INET){
29+
printf("Interface: %s\n", ifa->ifa_name);
30+
printf("Address: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_addr)->sin_addr));
31+
printf("Netmask: %s\n", inet_ntoa(((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr));
32+
}
33+
}
34+
35+
freeifaddrs(ifaddr);
36+
}

0 commit comments

Comments
 (0)