c# - determine Ethernet Adapter Local Area Connection IPv4 Address from Multiple IP Addresses returned -
i using below code retrieve ipv4 address (ethernet adapter local area connection). see multiple addresses being returned code. is there way of returned addresses ethernet adapter local area connection ip address ?
list<string> = new list<string>(); string hostname = dns.gethostname(); iphostentry hostentry = dns.gethostentry(hostname); foreach (ipaddress address in hostentry.addresslist) { if (address.addressfamily == addressfamily.internetwork) all.add(address.tostring() + "\n"); } datagridview2.datasource = all.select(x => new { value = x }).tolist(); } currently above code returns 3 values
- 172.20.***.***
- 192.168.***.***
- 192.168.***.***
ethernet adapter local area connection ip address 172.20.***.***
are maybe looking connection of properties networkinterfacetype , addressfamily?
foreach (var in networkinterface.getallnetworkinterfaces()) { console.writeline("{0} ({1})", i.name, i.networkinterfacetype); foreach (var in i.getipproperties().unicastaddresses) { console.writeline(" {0} ({1})", a.address, a.address.addressfamily); } } this give example:
local area connection (ethernet) (internetworkv6) 169.254.171.253 (internetwork)
Comments
Post a Comment