+8  A: 

MSDN says that IPAddress.Address property (which returns numeric representation of IP address) is obsolete and you should use GetAddressBytes method.

You can convert IP address to numeric value using following code:

var ipAddress = IPAddress.Parse("some.ip.address");
var ipBytes = ipAddress.GetAddressBytes();
var ip = (uint)ipBytes [3] << 24;
ip += (uint)ipBytes [2] << 16;
ip += (uint)ipBytes [1] <<8;
ip += (uint)ipBytes [0];

EDIT:
As other commenters noticed above-mentioned code is for IPv4 addresses only. IPv6 address is 128 bits long so it's impossible to convert it to 'uint' as question's author wanted.

aku
Are you sure about the four indices' order? it seems to me that byte with index 0 should be shifted 24 bits and not the one with index 3..
Andrei Rinea
A: 

I have never found a clean solution (i.e.: a class / method in the .NET Framework) for this problem. I guess it just isn't available except the solutions / examples you provided or Aku's example. :(

Andrei Rinea
+1  A: 

Byte arithmetic is discouraged, as it relies on all IPs being 4-octet ones.

Dmitry Shechtman
+4  A: 

Also you should remember that IPv4 and IPv6 are different lengths.

Corin
+1  A: 
var ipuint32 = BitConvertor.ToUInt32(IPAddress.Parse"some.ip.address.ipv4").GetAddressBytes());`
nt
BitConvertor.ToUINt32() takes two parameters (see http://msdn.microsoft.com/en-us/library/system.bitconverter.toint32.aspx)
mjv
+2  A: 

Shouldn't it be:

var ipAddress = IPAddress.Parse("some.ip.address");
var ipBytes = ipAddress.GetAddressBytes();
var ip = (uint)ipBytes [0] << 24;
ip += (uint)ipBytes [1] << 16;
ip += (uint)ipBytes [2] <<8;
ip += (uint)ipBytes [3];

?

Christo
OMG!!! This is how it should be. Aku's solution is not working..
Andrei Rinea
A: 
System.Net.IPAddress ipAddress = System.Net.IPAddress.Parse("192.168.1.1");

byte[] bytes = ipAddress.GetAddressBytes();
for (int i = 0; i < bytes.Length ; i++)
       Console.WriteLine(bytes[i]);

Output will be 192 168 1 1

qasali