Welcome to MSDN Blogs Sign in | Join | Help

Windows PowerShell One Liner: Name to IP Address

<Edited 7/2/2006 to add tags and category>
Wei Wu provided a nice one liner in response to a query in our NewsGroup: Microsoft.Public.Windows.PowerShell about how to resolve a hostname into an IP Address:

PS> [System.Net.Dns]::GetHostAddresses("www.msn.com")


IPAddressToString : 207.68.173.76
Address           : 1286423759
AddressFamily     : InterNetwork
ScopeId           :
IsIPv6Multicast   : False
IsIPv6LinkLocal   : False
IsIPv6SiteLocal   : False

 

If you want to go from address to name:

PS> [System.Net.Dns]::GetHostbyAddress("207.46.198.30")

HostName                  Aliases                  AddressList
--------                  -------                  -----------
wwwtkttest2.microsoft.com {}                       {207.46.198.30}

Jeffrey Snover
Windows PowerShell Architect

PSMDTAG:FAQ: How do I resolve a hostname?
PSMDTAG:DOTNET: GetHostByAddress

Published Monday, June 26, 2006 1:35 PM by PowerShellTeam
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# PowerShell - resolve a hostname into an IP Address

Jeffrey Snover posted this on the Powershell blog
&amp;nbsp;
Wei Wu provided a nice one liner in response...
Monday, June 26, 2006 10:13 AM by Ron Crumbaker at myITforum.com, Inc.

# re: Windows PowerShell One Liner: Name to IP Address

Once again PS shows it's stuff.

The ability for PS to call into NET makes PS one hell of a powerfull tool.
Thursday, June 29, 2006 3:20 PM by jvierra

# re: Windows PowerShell One Liner: Name to IP Address

Is there a way to create a DNS record (any type) using .net? I realize you can use WMI and the MicrosoftDNS namespace to do this however i am wanting to try out some .net via powershell and can't find a way to do it - is this possible?

I can see from this blog that retrieving DNS information is not a problem - what about writing to DNS???

Thanks in advance

Tuesday, August 21, 2007 4:59 PM by Err

# Get Computer by IP Address &laquo; Dmitry&#8217;s PowerBlog: PowerShell and beyond

# re: Windows PowerShell One Liner: Name to IP Address

> [System.Net.Dns]::GetHostAddresses("www.msn.com")

From the perspective of a System Admin, this is not a great answer.  Having to track through .Net libraries to find how to get an IP suggests PowerShell thinks like a developer, and not like a command line.

Too much typing just to get an IP; too much tracking through .Net libraries to find "how."  Admins don't just look up IPs, they have look up other types of records (NS, MX), track down why things don't resolve correctly by hitting other DNS servers....  

Why couldn't PowerShell just make an object oriented port of NSLookup?  What's next: we have to manually create ICMP packets and monitor for a response?

Sunday, April 27, 2008 6:22 PM by Eric

# re: Windows PowerShell One Liner: Name to IP Address

Just what I needed - Powershell rocks!

Still, for a seasoned Powershell user to reach the next level, a deeper understanding of the .net fw is necessary. So, this kind of post is priceless.

Thank You so much.

Tuesday, June 17, 2008 11:02 AM by Mauro Rita

# FuzzLinks.com &raquo; PowerShell Team Blog : Windows PowerShell One Liner: Name to IP Address

# re: Windows PowerShell One Liner: Name to IP Address

Does this work on all DNS names?

Tuesday, September 30, 2008 1:16 AM by find ip address

# re: Windows PowerShell One Liner: Name to IP Address

Great article, I was able to use it and with a minor modification do a quick reverse lookup so that we could translate a list of IPs into their respective hostname.

Monday, December 15, 2008 12:57 PM by JKav

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker