[IronPython] Access System.Net.NetworkInformation.GetAllNetworkInterfaces()
Dino Viehland
dinov at microsoft.com
Thu Aug 12 22:59:00 CEST 2010
Kristopher wrote:
> Hello All,
>
> First time crawling in .NET and was wondering how to access the list
> of network interfaces.
>
> I am following a C# example from MSDN that goes something like this:
>
> <C#>
>
> NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
>
> </C#>
> Then they iterate over adapters to list the interfaces.
>
> In IronPython, I am trying to do this:
>
> <IronPython>
> import clr
> clr.AddReference('System.Net')
> from System.Net import NetworkInterface
>
> a[] = NetworkInformation.GetAllNetworkINterfaces()
>
> </IronPython>
>
> Then I will iterate over a to list.
>
> It returns an Attribute error and says that GetAllNetworkInterfaces of
> 'NameSpace#' object is read only.
>
It's actually in System.Net.NetworkInformation:
>>> System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
Array[SystemNetworkInterface]((<System.Net.NetworkInformation.SystemNetworkInterface object at 0x000000000000002E [System.Net.NetworkInformation.SystemNetworkIn
terface]>, <System.Net.NetworkInformation.SystemNetworkInterface object at 0x000000000000002F [System.Net.NetworkInformation.SystemNetworkInterface]>, <System.N
et.NetworkInformation.SystemNetworkInterface object at 0x0000000000000030 [System.Net.NetworkInformation.SystemNetworkInterface]>))
You also don't need the clr.AddReference because this is in System.dll instead
of in System.Net.dll.
More information about the Ironpython-users
mailing list