要参照設定
System.Net.NetworkInformation;
public static void getDefaultGateway()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
GatewayIPAddressInformationCollection addresses =
adapterProperties.GatewayAddresses;
if (addresses.Count > 0)
{
foreach (GatewayIPAddressInformation address in addresses)
{
Console.WriteLine(address.Address.ToString());
}
}
}
}
adapter.Name
ネットワークアダプタの名前を取得
例)ローカル エリア接続
adapter.Id
ネットワークアダプタのID
例){A32F1F13-1CBD-4300-ADE6-D3AEA1426A52}
adapter.OperationalStatus
ネットワーク接続の現在の操作状態を取得
例)Up
adapter.Speed
ネットワークインターフェイスの速度を取得
例)100000000
adapter.Description
インターフェイスの説明を取得
例)Broadcom NetXtreme 57xx Gigabit Controller – パケット スケジューラ ミニポート