C
C#•14mo ago
MisterT

Need help on getting a list of IPv4 and IPv6 IP Addresses

This is what I have at the moment don't even now what it does, but ain't doing what I'm hoping pepecry public static List<string> GetLocalIPAddresses() { List<string> ipAddresses = new List<string>(); string hostName = Dns.GetHostName();
IPHostEntry hostEntry = Dns.GetHostEntry(hostName); foreach (IPAddress ip in hostEntry.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { ipAddresses.Add(ip.ToString()); } else if (ip.AddressFamily == AddressFamily.InterNetworkV6 && !ip.IsIPv6LinkLocal) { ipAddresses.Add(ip.ToString().Split('%').FirstOrDefault()); } } if (!ipAddresses.Contains("127.0.0.1")) { ipAddresses.Insert(0, "127.0.0.1"); } return ipAddresses; }
6 Replies
jcotton42
jcotton42•14mo ago
and what are you hoping for?
MisterT
MisterTOP•14mo ago
its kinda hard to explain as im clueless in this but believe i'm supppose to get something like this wheres as im only receiving last to and one op ipv6 as fe: something if that anymore 😄
No description
jcotton42
jcotton42•14mo ago
but what characteristics are you looking for in the IPs?
MisterT
MisterTOP•14mo ago
as i understand the user should be able to choose from a list of available ipv4 and ipv6 connections available on the computer like ethernet bluetooth local wifi and what not sorry if that doesn't help that's all i really know 😄
MisterT
MisterTOP•14mo ago
Thanks a lot!

Did you find this page helpful?