Last active
January 28, 2016 20:40
-
-
Save Sebbyastian/565fe44bf6ad55b80eb5 to your computer and use it in GitHub Desktop.
get_network_params.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* gcc -std=c11 get_network_params.c -lws2_32 -liphlpapi -o get_network_params.exe */ | |
#include <winsock2.h> | |
#include <iphlpapi.h> | |
#include <stdio.h> | |
int main(void) { | |
FIXED_INFO *fixed_info = (FIXED_INFO[]) { 0 }; | |
ULONG fixed_info_size = 0; | |
GetNetworkParams(fixed_info, &fixed_info_size); | |
fixed_info = malloc(fixed_info_size); | |
if (fixed_info == NULL) { | |
puts("Error calling malloc... :("); | |
return 0; | |
} | |
if (GetNetworkParams(fixed_info, &fixed_info_size) != NO_ERROR) { | |
puts("Error calling GetNetworkParams... :("); | |
return 0; | |
} | |
printf("Host Name: %s\n", fixed_info->HostName); | |
printf("Domain Name: %s\n", fixed_info->DomainName); | |
char *prefix_msg = "DNS Servers: "; | |
int indentation = 0; | |
for (IP_ADDR_STRING *n = &fixed_info->DnsServerList; n; n = n->Next, prefix_msg = "") { | |
indentation = printf("%*s", indentation, prefix_msg); | |
printf("%s\n", n->IpAddress.String); | |
} | |
printf("Node Type: %s\n", fixed_info->NodeType == BROADCAST_NODETYPE ? "Broadcast node" | |
: fixed_info->NodeType == PEER_TO_PEER_NODETYPE ? "Peer to Peer node" | |
: fixed_info->NodeType == MIXED_NODETYPE ? "Mixed node" | |
: fixed_info->NodeType == HYBRID_NODETYPE ? "Hybrid node" | |
: "Unknown node"); | |
printf("DHCP scope name: %s\n", fixed_info->ScopeId); | |
printf("Routing: %s\n", fixed_info->EnableRouting ? "enabled" : "disabled"); | |
printf("ARP proxy: %s\n", fixed_info->EnableProxy ? "enabled" : "disabled"); | |
printf("DNS: %s\n", fixed_info->EnableDns ? "enabled" : "disabled"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment