[C#] SubnetMask 구하기

How to get subnetmask in C#

 

using System.Net;
using System.Net.NetworkInformation;

private void showSubnetMask() 
{ 
	NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); 
    string subnetMask = string.Empty;
        
    foreach (NetworkInterface adapter in adapters) 
    { 
    	IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); 
        
        foreach (UnicastIPAddressInformation uipi in adapterProperties.UnicastAddresses)
        {
        	if (uipi.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetWork)
            {
            	if (adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                {
                	subnetMask = uipi.IPv4Mask.ToString();
                }
            }
        }
	}
	string msg = "SubnetMask : " + subnetMask; 
	MessageBox.Show(msg,"info",MessageBoxButton.OK, MessageBoxIcon.Information); 
    return; 
}

'Programming > C#' 카테고리의 다른 글

[C#] SubnetMask 구하기  (0) 2019.08.30
[C#] DNS서버 구하기  (0) 2019.08.29
[C#] Gateway 구하기  (0) 2019.08.28
[C#] 로컬 IP 주소 구하기  (0) 2019.08.27
[C#] 수행시간 구하기  (0) 2018.08.21
[C#/WinForm] 창 크기 조절하기  (0) 2018.08.20

[C#] DNS 서버 구하기

How to get DNS in C#

using System.Net;
using System.Net.NetworkInformation;

private void showDnsServer()
{

    NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    ArrayList dnsAddrList = new ArrayList();
    
    foreach (NetworkInterface adapter in adapters)
    {
    	IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        
        if (adapter.OperationalStatus == OperationalStatus.Up & adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
        {
        	IPAddressCollection dnsAddres = adapterProperties.DnsAddresses;
            foreach (IPAddress dns in dnsAddres)
            {
            	dnsAddrList.Add(dns.ToString());
            }
        }
    }
    
    string msg = "DNS : " + dnsAddrList[0] + "\r\n" + "DNSSub : " + dnsAddrList[1];
    MessageBox.Show(msg,"info",MessageBoxButton.OK, MessageBoxIcon.Information);
    return;
}

 

'Programming > C#' 카테고리의 다른 글

[C#] SubnetMask 구하기  (0) 2019.08.30
[C#] DNS서버 구하기  (0) 2019.08.29
[C#] Gateway 구하기  (0) 2019.08.28
[C#] 로컬 IP 주소 구하기  (0) 2019.08.27
[C#] 수행시간 구하기  (0) 2018.08.21
[C#/WinForm] 창 크기 조절하기  (0) 2018.08.20

[C#] Gateway 구하기

How to get gateway in C#

 

using System.Net.NetworkInformation;

privite void showGateway()
{
	NetworkInterface[] adapters  = NetworkInterface.GetAllNetworkInterfaces();
    
    string gateway = string.Empty;
    
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
        GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;
        if (addresses.Count >0)
        {
            foreach (GatewayIPAddressInformation address in addresses)
            {
                gateway = address.Address.ToString());
            }
            Console.WriteLine(gateway);
        }
    }
}

 

 

'Programming > C#' 카테고리의 다른 글

[C#] SubnetMask 구하기  (0) 2019.08.30
[C#] DNS서버 구하기  (0) 2019.08.29
[C#] Gateway 구하기  (0) 2019.08.28
[C#] 로컬 IP 주소 구하기  (0) 2019.08.27
[C#] 수행시간 구하기  (0) 2018.08.21
[C#/WinForm] 창 크기 조절하기  (0) 2018.08.20

+ Recent posts