Retrieve IPv4 and IPv6 nameservers programmatically
You really should not access the _u._ext
parts of the resolver state, they are an internal implementation detail. The nscount6
member is currently unused and always zero. It had to be kept to avoid changing the ABI as the result of struct offset/size changes.
If you need the nameserver list, you should parse /etc/resolv.conf
yourself. Note that eventually, glibc will also support more than three name servers, and those extra resolvers will not be reflected in the public resolver state.
Get IPv6 DNS Server Addresses using GetAdaptersAddresses()
You're passing the wrong data to inet_ntop
. You should pass the sin_addr
or sin6_addr
member, depending on the protocol.
inet_ntop(AF_INET, &((struct sockaddr_in*)pDnServer->Address.lpSockaddr)->sin_addr, ipv4_addrstr, INET_ADDRSTRLEN);
inet_ntop(AF_INET6, &((struct sockaddr_in6*)pDnServer->Address.lpSockaddr)->sin6_addr, ipv6_addrstr, INET6_ADDRSTRLEN);
How to get IPv4 and IPv6 address of local machine?
string strHostName = System.Net.Dns.GetHostName();;
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
Console.WriteLine(addr[addr.Length-1].ToString());
if (addr[0].AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
{
Console.WriteLine(addr[0].ToString()); //ipv6
}
Related Topics
How to View Thread Id of a Process Which Has Opened a Socket Connection
Movdqu Instruction + Page Boundary
How to Feed Awk Input from Both Pipe and File
Dockerfile Cmd 'Command Not Found'
Escaping the Exclamation Point in Grep
How to Sort Comma Separated Values in Bash
How Kernel Notify a User Space Program an Interrupt Occurrs
Linux Script- Date Manipulations
Resolve Relative Relocations in Partial Link
Bash Script Properties File Using '.' in Variable Name
How to Make Linux Power Off When Halt Is Run
Python3 Unicodeencodeerror When Run via Synology Task Scheduler
Delete Last Line Break Using Sed