Tuesday, July 15, 2008

With the help of Kuma:

http://groups.google.com/group/microsoft.public.windows.powershell
/browse_thread/thread/9b10ea1270dfd0ad/eb78a0bc226837d6#eb78a0bc226837d6

I have picked up this gem, which gives all the physical IPs on a system:

0..1 | %{([System.Net.DNS]::GetHostEntry(""))
.AddressList[$_].IPAddressToString}

Monday, July 7, 2008

/\/\o\/\/ came up with the following brilliance:
http://thepowershellguy.com/blogs/posh/archive/2008/06/30/powershell-get-ipconfig-function.aspx?
CommentPosted=true#commentmessage

[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
|% {$_.getIPProperties().UnicastAddresses[0]}


Address : 192.168.0.5
IPv4Mask : 255.255.255.0
IsTransient : False
IsDnsEligible : True
PrefixOrigin : Dhcp
SuffixOrigin : OriginDhcp
DuplicateAddressDetectionState : Preferred
AddressValidLifetime : 349435
AddressPreferredLifetime : 349435
DhcpLeaseLifetime : 349435

Address : 127.0.0.1
IPv4Mask :
IsTransient : False
IsDnsEligible : True
PrefixOrigin : Manual
SuffixOrigin : Manual
DuplicateAddressDetectionState : Preferred
AddressValidLifetime : 3079514780
AddressPreferredLifetime : 3079514780
DhcpLeaseLifetime : 3079514780




[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()
|% {$_.getIPProperties}


MemberType : Method
OverloadDefinitions : {System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties()
Name : GetIPProperties
IsInstance : True

MemberType : Method
OverloadDefinitions : {System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties()
Name : GetIPProperties
IsInstance : True

MemberType : Method
OverloadDefinitions : {System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : System.Net.NetworkInformation.IPInterfaceProperties GetIPProperties()
Name : GetIPProperties
IsInstance : True

Sunday, July 6, 2008

I find it simply amazing that Powershell can use the .NET to find the Broadcast and Loopback with little complication, but not the host IP Address:
[System.Net.IPAddress]::Broadcast.IPAddressToString
or
[System.Net.IPAddress]::Loopback.IPAddressToString

I can find all NetworkInterface information BUT the IP easily enough:
[System.Net.NetworkInformation.NetworkInterface]::
GetAllNetworkInterfaces()

But if I want my local host IP address through .NET I need some kludge like:
$host_name = [System.Net.Dns]::GetHostName() ; [System.Net.Dns]::Resolve("$host_name")

Or I can dredge up some other not quite satisfactory kludge from gwmi:

$NetworkInfo =gwmi -query "SELECT * FROM Win32_NetworkAdapterConfiguration"
function NetworkInfoSort {$NetworkInfo | Select-Object IPAddress,Description,Index,DefaultIPGateway | sort-object Index}
NetworkInfoSort

gwmi -class win32_NetworkAdapterConfiguration | %{ $_.IPAddress }

gwmi -query "SELECT IPAddress FROM Win32_NetworkAdapterConfiguration" | Select IPAddress

I wish I could just do something like:

[System.Net.IPAddress]::LocalHost.IPAddressToString
or
[System.Net.NetworkInformation.NetworkInterface]::
GetAllNetworkInterfaces.IPAddress
or
Get-ipconfig

Wednesday, July 2, 2008

Still relatively confused on how to use the .NET through Powershell. Here are some simple examples that were easy to find because they have accessible overloaded interfaces (??):

$Ping = new-object System.Net.NetworkInformation.ping
$Ping.Send("192.168.0.1")
Status : Success
Address : 192.168.0.1
RoundtripTime : 1 ms
BufferSize : 32
Options : TTL=127, DontFragment=False


[System.Net.Dns]::Resolve("google.com") | fl *
HostName : google.com
Aliases : {}
AddressList : {64.233.167.99, 72.14.207.99, 64.233.187.99}


[System.Net.Dns]::GetHostName()
rmfmedia

[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()

Id : {0348D5D7-6D83-44C8-B556-B29466698340}
Name : Wireless Network Connection
Description : Intel(R) PRO/Wireless 3945ABG Network Connection - Packet Scheduler Miniport
NetworkInterfaceType : Ethernet
OperationalStatus : Up
Speed : 54000000
IsReceiveOnly : False
SupportsMulticast : True
....

[System.Net.NetworkInformation.NetworkInterface]::GetIsNetworkAvailable()
True