Reputation: 43
I have this code
public static TcpConnectionInformation[] getConnections()
{
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpInfoList = properties.GetActiveTcpConnections();
return tcpInfoList;
}
But sometimes that code return MAC addresses(like ::ffff:0:f7ad:645d) instead of ip, anybody know how to fix it?
Upvotes: 1
Views: 308
Reputation: 28849
That's not a MAC address, it's an IPv6 address. You can filter your result to only show IPv4 addresses, as Legend shows.
Upvotes: 4
Reputation: 6038
Have you tried this?
IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
}
}
return localIP;
Upvotes: 2