ASP.NET Tips: Printing an IP Address

So while looking through a dump, you will sometimes come across an IP Address.  For example, the System.Net.IPAddress:


If you look at this output, you can see that we have the address in the m_Address field, but what is 1895899146?  This is where the function !printipaddress comes into play.  This is in the clr10\sos version of sos and works on 1.x versions of .NET.  All you have to do is pass it the System.Net.IPAddress object or the m_Address value.


Very easy then to get the IP Address that we are dealing with.  If you really want to do this by hand, you can do the following.  Convert it to Hex, then break it up into bytes and look at them in reverse order.

So this number in hex would be 0x7101200a.  So breaking that up would be 71 01 20 0a.  Reversing them would be 0a 20 01 71.  And now back to decimal gives you 10 32 1 113 (the IP Address we see above).


For .NET 2.0 versions, there is an alternative method to getting the IP Address.  There is a member m_ToString and if you !dumpobj that address, you will see the IP address.  Hope that helps those of you using the newer version of .NET.

kick it on