본문 바로가기

.NET/NetWork

IPInterfaceProperties를 이용한 네트워크 정보 출력

반응형
using System.Net.NetworkInformation; // 추가


AnycastAddresses // 네트워크인터페이스의 애니캐스트 정보를 가져옴
DhcpSercerAddresses //DHCP 서버 주소 정보를 가져옴
DnsAddresses // DNS 서버 주소 정보를 가져옴
GatewayAddresses //네트워크 인터페이스의 게이트웨이 정보를 가져옴
IsDnsEnables //DNS 서버에 쿼리를 보낼 수 있는지에 대한 정보를 Booleam형태로 가져옴


static void Main(string[] args)
{
DisplayNetworkInfo();
}

private static void DisplayNetworkInfo()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
GatewayIPAddressInformationCollection Gatewayaddresses = adapterProperties.GatewayAddresses;
IPAddressCollection dhcpServer = adapterProperties.DhcpServerAddresses;
IPAddressCollection dnsServers = adapterProperties.DnsAddresses;
Console.WriteLine("네트워크 카드 : " +adapter.Description); //네트워크 정보
Console.WriteLine("physical Address.........: " , adapter.GetPhysicalAddress());

}
}