[C#] 네트워크 정보 구하기
using System;
using System.Net;
using System.Management;
namespace GetIPCS
{
/// <summary>
/// Gets IP addresses of the local machine
/// </summary>
class classGetIPCS
{
/// <summary>
/// Gets IP addresses of the local machine
/// </summary>
[STAThread]
static void Main(string[] args)
{
ManagementObjectSearcher query = new ManagementObjectSearcher
(”SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=’TRUE’”);
ManagementObjectCollection queryCol = query.Get();
foreach (ManagementObject mo in queryCol)
{
string[] address = (string[])mo["IPAddress"];
string[] subnets = (string[])mo["IPSubnet"];
string[] defaultgateways = (string[])mo["DefaultIPGateway"];
Console.WriteLine(”Network Card: {0}”, mo["Description"]);
Console.WriteLine(” MAC Address: {0}”, mo["MACAddress"]);
foreach (string ipaddress in address)
{
Console.WriteLine(” IP Address: {0}”, ipaddress);
}
foreach (string subnet in subnets)
{
Console.WriteLine(” Subnet Mask: {0}”, subnets);
}
foreach (string defaultgateway in defaultgateways)
{
Console.WriteLine(” Gateway: {0}”, defaultgateway);
}
}
}
}
}